I
I
idr19952020-06-12 21:58:32
Python
idr1995, 2020-06-12 21:58:32

Why doesn't it open regular files in Microsoft Visual Studio Code?

I'm asking you to open a file. Doesn't open. I use Microsoft VS code, python,
I can't simply open the file in the interpreter, what am I doing wrong?

I am requesting two files:

file = open('data.txt', 'r')
file = file.read()
print(file)

with open('data1', 'r') as new_file:
    line = new_file.readline()
print(line)


and this is what it outputs:
PS C:\Users\mrrin> & C:/Users/mrrin/Anaconda3/python.exe "c:/Users/mrrin/Desktop/visual studio code/Untitled-1.py"

Traceback (most recent call last):
  File "c:/Users/mrrin/Desktop/visual studio code/Untitled-1.py", line 5, in <module>
    with open('blyad', 'r') as new_file:
FileNotFoundError: [Errno 2] No such file or directory: 'data1'
PS C:\Users\mrrin>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
milssky, 2020-06-12
@idr1995

And the file "data1" does not exist in the directory with your script. That's why you can't open it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question