Ask Your Question
1

truncated output problem?

asked 2016-10-26 13:34:53 -0500

moati gravatar image

Hi,

I have created a polyhedron out of a number of vertices and whenever I try to write its H-representation to a file, the inequalities are somehow truncated!

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

Any idea why is that?

Thanks,

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-10-27 07:58:58 -0500

updated 2016-10-27 08:00:20 -0500

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2016-10-26 13:34:53 -0500

Seen: 20 times

Last updated: Oct 27 '16