4 reading what is wrong with my code


#1

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


#2

Hi @corepro50273,

As Instruction number two reads:

Next, print the result of using .read() on my_file, like the example above.

In your code you use three .readline() which, you guessed it, prints only 3 lines from output.txt

Erasing two of your prints and modifying the remainder to .read() like so will work:

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

print my_file.read()

my_file.close()

Good luck! :smile:


#3

you didn't help at all! :anguished:


#4

Hi @arcrockstar77414,

Could you be more specific?

Are you encountering a problem with this exercise as well? If so, what is the nature of the problem and could you paste your code in the forum so we can try to help you?

Thanks!


#5

This looks like the code for the next exercise, not the 4th.


#6

I used your code but it returned:

Traceback (most recent call last):
File "python", line 1, in
IOError: [Errno 2] No such file or directory: 'output.txt'

and
Oops, try again. Did you create a variable called my_file?

I can you help me?


#7

oh, I fixed it eventually, turn out you have to clear the numbers from the output.txt file which were created from last lesson =(((


#8

hello, the code is:
my_file = open("text.txt","r")
print my_file.readline()
print my_file.readline()
print my_file.readline()
my_file.close()


#9

thx a lot man, got stuck at the same place


#10

How did you fix it? I tried to go back to lesson 3 to delete the info in output.txt but it was still there in lesson 4. Please help.


#11

delete the output from lesson 4 output,txt file.