5/9 Reading between the lines. I'm getting a different error from everyone else


#1



https://www.codecademy.com/courses/python-intermediate-en-OGNHh/1/1?curriculum_id=4f89dab3d788890003000096#

I don't know why this won't read the lines. I get this error message:

Oops, try again. There seems to be something not quite right with your code - see the console window for the error message.

The console window prints this:

Traceback (most recent call last):
File "python", line 2, in
AttributeError: 'tuple' object has no attribute 'readline'


my_file = ("text.txt", "r")
print my_file.readline()
print my_file.readline()
print my_file.readline()
my_file.close()


#2

comma-separated values create a tuple. You assigned a tuple to your name my_file

Go look up how to open files. And make sure that you understand how the error message relates to this so that you better understand similar error messages later.


#3

you forgot the open() function on the first line to open() text.txt It should look like:

my_file = open("text.txt", "r")
print my_file.readline()
print my_file.readline()
print my_file.readline()
my_file.close()


#4

my_file = open("text.txt","r")

print my_file.readline()
print my_file.readline()
print my_file.readline()

my_file.close()

it is giving me error like
"Traceback (most recent call last):
File "python", line 1, in
IOError: [Errno 2] No such file or directory: 'text.txt' "


#5

yeah,i got the same problem


#6

Exactly even i got the same problem .Somebody please tell how to get rid of this problem?


#7

same issue here. I think there must be a link missing to the file in the test code


#8

I shed some light on the subject, please check it out


#9

Answer is here ,

Click here!


#10

Check here,

Click!


#11

my_file=open('text.txt','w')
my_file=open('text.txt','r')
print my_file.readline()
print my_file.readline()
print my_file.readline()
my_file.close()

This should work