Ask Your Question
1

truncated output problem?

asked 8 years ago

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,

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 8 years ago

slelievre gravatar image

updated 8 years ago

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

Preview: (hide)
link

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: 8 years ago

Seen: 311 times

Last updated: Oct 27 '16