Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I can't open .txt or csv file

Trying to open file

I’m learning python as my first programing language and i’ve been trying to open this .txt file and it says that can’t find it

-Tried to specify as much de file direction (besides being in the same folder)
-Tried deleting the files and coding everything again

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

For future questions, please provide the code in the question as text (attaching a screenshot is fine but make sure to add the code either in the question or a pastebin link)

The problem is your working directory is set to the Curso Python folder and not Curso Python folder/Curso de dalto which actually contains the folder and file you are trying to open.

The path of the file you specified is a relative path relative path which means it’s your current working directory + the path you specified.

When running a python script, the directory you run it from is set as the default working directory. If you change your directory in the terminal using cd Curso de dalto and then run the code it should run.

Another tip, you can always check the current working directory in python using:
import os print(os.getcwd())

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading