The open() function


why is it when i put in this exact same line of syntaxes in both my own python interpreter and interpreter , it says
File "python", line 1, in
IOError: [Errno 2] No such file or directory: 'output.txt'
?it works in my exercise on codecademy

my_list = [i**2 for i in range(1,11)]

my_file = open("output.txt", "r+")



What happens if you change output.txt to text.txt?


now it comes up with this

File "python", line 3, in
IOError: [Errno 2] No such file or directory: 'text.txt'


Have you considered what your code does? It opens a file. If that file doesn't exist, then you'll get told so.


The files exist as part of the lesson.


i see,thanks for those explanation!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.