The open() function


#1


why is it when i put in this exact same line of syntaxes in both my own python interpreter and repl.it 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+")


#2

Hello

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


#3

hi!
now it comes up with this

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


#4

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


#5

The files exist as part of the lesson.


#6

i see,thanks for those explanation!


#7

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