Ask Your Question
1

truncated output problem?

asked 2016-10-26 20:34:53 +0100

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 14:58:58 +0100

slelievre gravatar image

updated 2016-10-27 15:00:20 +0100

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 20:34:53 +0100

Seen: 289 times

Last updated: Oct 27 '16