+ 1
Why name "file" is not defined?
Hi, there. I wanna the code to read a file named 1.txt and print the contents on the screen. So I used the file scription introduced in Solo learn, but when I run codes on my PC, it returned with error message. CODE: text = open("D:/1.txt","r") ptxt = file.read() print(ptxt) file.close() TERMINAL: file.py, line 2, in<module> ptxt = file.read() NameError: name "file" is not defined. ENVIRONMENT: WIN10 64 BIT, PYTHON 3.7 64 BIT
1 Odpowiedź
0
text.read()
...
text.close()