5/9 Refresh Page


#1



I am getting an error to refresh the page and not to worry that my code is saved(which it is). But no matter how many times I refresh the page, I still get the same error. I have tried using this on multiple browsers but still getting the same error. Any idea what is causing the error?


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


#2

Please post your full code for this exercise.

The code looks fine to me.


#3

That is my full code. I don't understand why I keep getting an error saying to refresh the page. I assume it is a bug of some sort, but I wanted to see if anyone found a way around it.


#4

Okay, yeah, I think there is a bug.

This is how I resolved it.

import os
print "==show us the existing files =="
files = [f for f in os.listdir('.') if os.path.isfile(f)]
for f in files:
    print str(f)
#my_file.close()
print "== if the file doesn't exist, create one =="
if os.path.exists('text.txt'):
    print "File exists"
else:
    print "Creating the text.txt-file"
    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()

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

Strange right? :slight_smile:


5/9 Bug
#5

Ya it was weird. That seems to work. Thanks for the help!!


#6

You're welcome.

A bug I guess.


#7

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