-3

I am running python 3.7 in Wing IDE as an administrator.

The python file is in the same folder (Documents) as the textdoc file.

This is the python code I have:

file = open("textdoc.txt", "r")

print(file.readlines())

file.close()

This is the content of the notepad (.txt) file called textdoc:

blue

red

green

When I run the program, I get this error:

Traceback (most recent call last):
  Python Shell, prompt 2, line 3
builtins.FileNotFoundError: [Errno 2] No such file or directory: 'textdoc.txt'

Another issue is that while I am able to create and write to files in Python using the write mode, I can't actually find the text file that was created anywhere in case I want to edit it manually.

1

1 Answer 1

0

I think that your two questions are actually the same, that is, your python execute your code at another dir. Try to execute it in the command-line:

cd /path/to/your/program
# Check if your file is there
# For windows:
DIR
# For Linux or MacOS:
ls
# Execute python script:
python pyscript.py
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.