0
I have already searched several topics here, unsuccessfully however. So, if there is already an equal question, please forgive me and indicate a solution. My project is articulated as follows:
linuxServer # /
----bin
----data
----arquivoCsv.csv
----packages
----lib
----module
----module.py
__init.py__
main.py
My idea is to use the module.py to call the fileCsv.csv. I can’t run the csv reader inside module.py. But if I test on main.py it works:
functional:
#linuxServer/main.py
import csv
somelist = []
with open('data/arquivoCsv.csv', 'r', encoding='ISO-8859-1')as csvFile:
itens = csv.reader(csvFile, delimiter =';')
for line in itens:
somelist.append(line)
Nonfunctional:
#linuxServer/package/lib/module/module.py
import csv
somelist = []
with open('linuxServer/data/arquivoCsv.csv', 'r', encoding='ISO-8859-1')as csvFile:
itens = csv.reader(csvFile, delimiter =';')
for line in itens:
somelist.append(line)
FileNotFoundError: [Errno 2] No such file or directory: 'linuxServer/data/arquivoCsv.csv'
PS: tips if the legal structure or need to change something will be welcome.
you tried to use
'../data/arquivoCsv.csv'
?? In fact../../../
. But this would not be the best option. Themodulo.py
is imported bymain.py
?– Paulo Marques
Yes, it gives the same error: Filenotfounderror: [Errno 2] No such file or directory: '.. /data/fileCsv.csv' Yes, the.py module is imported into main.py
– Érico Piantkoski
If you are having difficulties in the file and are using a gnu/linux open the terminal in the folder csv and a pwd for it to show the path and paste in the csv reading direction.. Or inside the folder that the python files put the csv.. thus becoming open('arquivoCsv.csv')
– stack.cardoso
The issue is that I don’t want to change any file from place. To on mac, hence pdw doesn’t work
– Érico Piantkoski