1

Error OSError: [Errno 36] File name too long: for the following code:

from importlib_resources import open_text
import pandas as pd

with open_text('package.data', 'librebook.txt') as f:
    input_file = f.read()

dataset = pd.read_csv(input_file)

Ubuntu 20.04 OS, this is for a python package, init.py file

I dont want to use .readlines()

Can I structure this code differently to not have this outcome occur? Do I need to modify my OS system? Some of the help I found looked to modify OS but dont want to do this if I dont need to. Thank you.

Stackaccount1
  • 139
  • 1
  • 12

2 Answers2

1

why not just pass in the name of the file and not the contents

dataset = pd.read_csv('librebook.txt')
foobar8675
  • 1,215
  • 3
  • 16
  • 26
  • Thank you, I don't believe this will work with the python package structure and file importing. Before I ported my code into the package, I had it structured like this. – Stackaccount1 Sep 22 '21 at 22:13
  • i'm not following why it wouldn't work, but if you want another example of reading a csv into pandas, here's a stack overflow . https://stackoverflow.com/questions/26903304/reading-data-from-a-csv-file-in-python/26903501 . reading a csv int o pandas is pretty common. – foobar8675 Sep 22 '21 at 23:41
  • the way the package is structured I cannot do dataset = pd.read_csv('librebook.txt') the package will not know where to find the file – Stackaccount1 Sep 23 '21 at 03:32
0
from importlib_resources import path
import pandas as pd

with path('package.data', 'librebook.txt') as f:
    dataset = pd.read_csv(f)
Stackaccount1
  • 139
  • 1
  • 12