Problem with lesson "Reading betwing the lines"


#1

IOError: [Errno 2] No such file or directory: 'text.txt'


#2

I had the same problem, what I did to fix it was:

To try and find the problem I decided to look back on previous tasks and see how they were formatted and how I could adapt it to my code. Then I found out that it would be easier to create my own text file and read that! I just added the following code to the START of my program:

my_file = open("text.txt", "w")
my_file.write("I'm the first line of the file!" + "\n")
my_file.write("I'm the second line." + "\n")
my_file.write("Third line here, boss." + "\n")
my_file.close()

Good luck, hope this helps you!!!


#3

Thanks!
This work perfectly!


#4

You don't need to write that, you just have to edit text.txt and it works fine


#5

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

my_file.close()

the program runs.


#6

Just open the file by clicking on it and add some text. Worked fine for me.


#7

worked for me as well.. the same ... what a mess .. i am trying to solve it in 3.11 am morning ... and i was buzzed in such simple code!


#8

worked for me as well.. the same ... what a mess .. i am trying to solve
it in 3.11 am morning ... and i was buzzed in such simple code!


#9

no no we just have to go to file and do some changes