3/9 error


I have an error, even though the tutorial has given me the OK to go on. Nothing's been written to output.txt, it looks empty. Can someone show me what my problem is? Thanks in advance.



myList = [ i**2 for i in range(1,11) ]
print myList
#create a file and add line's
myFile =open("output.txt", "w+")
for item in myList:
    #print item
    myFile.write(str(item) + "\n")

#read a file, all at once !!
f = open("output.txt","r")
#print f
line = f.read()
print line
print "-- End of File was reached --"

# Read a file, line by line
f = open("output.txt","r")
print "-- Begin of File --"
while line != "":
    line = f.readline()
    print line,
print "-- End of File was reached --"

= http://stackoverflow.com/questions/2967194/open-in-python-does-not-create-a-file-if-it-doesnt-exist
= https://docs.python.org/2/tutorial/inputoutput.html

3/9 Writing

Sounds like in 1/9, something gets imported that we can't see?
And if you try to execute 2/9 and 3/9 without first submitting 1/9, then an error occurs. But if you run 1/9 first, then 2/9 and 3/9 write to output.txt just fine.

I don't understand what's taking place in 1/9 that makes this occur.


That works for me. I've changed parametr "r+" for "w"

my_list = [i**2 for i in range(1,11)]

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

Add your code below!

for i in my_list:
my_file.write(str(i) + '\n')



Please re-edit your Post by selecting your code
then =click=ing the </> button of your editor,
and then use the indentation in your
python-code .....


i'd rather made a screenshot, should be more readable


my_list = [i**2 for i in range(1,11)]

my_file = open("output.txt", "r+")
for item in my_list:
#print item
my_file.write(str(item) + "\n")



You should clear "output.txt" before submitting your code.



I've noticed the same thing. If I just run the code in 3/9, then I get an error saying output.txt doesn't exist (even though the autograder give me a green light to go ahead.) If I go back and run 1/9 and 2/9 and then 3/9, then no problem. I had the same problem finishing 2/9.


it worked for me...