Reading Between the Lines


#1

my_file = open("text.txt","r+")
my_file.write("yossef\ngamal\nnagy")
print my_file.readline()
print my_file.readline()
print my_file.readline()

my_file.close()

error:
Oops, try again. Sorry, but I'm gonna need you to refresh the page! Don't worry your code is saved.
please help me on this
i did but i didnt work


#2

Hello @letmeprogramyou1,

Could you please attach a link to the exercise you are on? Python's File IO has been know to have a few glitches here and there... :smile:


#3

https://www.codecademy.com/courses/python-intermediate-en-OGNHh/1/1?curriculum_id=4f89dab3d788890003000096
here is the link i passed all exercises except this 99% the course of python :relaxed: i wonna just see the badge that i finished python :smile_cat:


#4

I am having the same problem here.


#5

First line should only be r not r+.

Also,
remove this line

And manually write a few lines in the text.txt file.

  1. any text...
  2. any text...
  3. any text...

It should work after correcting these errors.

Same goes for you @courserunner56143


#6

OK. I'm getting the same error.

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

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

Oops, try again.
Sorry, but I'm gonna need you to refresh the page! Don't worry your code is saved.

In the output window, it says (which seems like for some reason the session is not able to see text.txt file but I can see the contents in text.txt file successfully in 2nd tab):

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

#7

I like your crave for the badge. It would be fun if we can show it in our Linkedin profile but I'm not sure if there's any way to show our badges that we earned from CodeAcademy in Linkedin.


#8

OK found the solution.

My code was GOOD (as requested in the exercise).

All I did to solve / pass the error shenzi was to GO TO THE "TEXT.TXT" file tab, enter a new line there, removed it.

Re-ran my code and I'm now smiling that it worked.

Enjoy!


#9

Can you send this worked code?


#10

I had the same issue and did as you said. Works now, thanks so much :slight_smile:


#11

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