Skip to content Skip to sidebar Skip to footer

Writing To A File With Xyz Format

I want to write x points and y points in a trajectory file with the xyz format. But I am a beginner in python, and this code gives the error unexpected character after line contin

Solution 1:

The problem is this line, with the character \ (which python may think is a line continuation character in certain contexts). When you fix that, you'll also have the problem that %8x and %8z are illegal formatting characters. I don't know exactly what you want, but %s might work.

To solve those two problems, change this:

xyz.write('%s,%8x,%8y,%8z'\'n%(xpoints,ypoints,0)')

to this:

xyz.write('%s,%8s,%8s,%8s\n' % (xpoints,ypoints,0))

Post a Comment for "Writing To A File With Xyz Format"