Ask Your Question

Revision history [back]

You need to close the file when you are done writing to it.

o = open('test.out','w')
for l in triangle.Hrepresentation():
    o.write(str(l) + "\r")
o.close()

Even better, you can use with as follows:

with open('test.out','w') as o:
    for l in triangle.Hrepresentation():
        o.write(str(l) + "\r")

The file is closed when the with block ends.

You need to close the file when you are done writing to it.

o = open('test.out','w')
for l in triangle.Hrepresentation():
    o.write(str(l) + "\r")
o.close()

Even better, you can use with as follows:

with open('test.out','w') as o:
    for l in triangle.Hrepresentation():
        o.write(str(l) + "\r")

The file is closed when the with block ends.

Find this explained in the Python documentation: https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files