Finding files - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Finding files (/thread-14605.html) |
Finding files - knollfinder - Dec-09-2018 I am using an iMac with OS 10.12.6. I downloaded 3.7.1, and, using IDLE in the shell, I tried to read an existing text file with f = open("entity_list.txt")which resulted in a message that the file could not be found. The file is in the same folder that the Python was installed in. RE: Finding files - jeanMichelBain - Dec-09-2018 You should give more details about the error. I tested your code, and I founded it works. The error in the first run is because there is no file (this is normal), and that was corrected by creating a file (touch command). The test was made on linux, but I'm pretty sure you will get the same results on another OS. You could check there is a real file, at the right place, with the correct access right, and give us a feedback. $ cat openFile.py f = open("entity_list.txt") $ python openFile.py Traceback (most recent call last): File "openFile.py", line 1, in <module> f = open("entity_list.txt") IOError: [Errno 2] No such file or directory: 'entity_list.txt' $ touch entity_list.txt $ python openFile.py $ python3 openFile.py $ RE: Finding files - Gribouillis - Dec-09-2018 You can get more information from python from pathlib import Path wd = Path.cwd() print("The current directory is {}".format(wd)) for p in wd.iterdir(): print(p.name) |