问题
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 continuation character. The first line is number of atoms, second line is a comment, and third line is coordinates.
xyz.close()
回答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))
来源:https://stackoverflow.com/questions/34680336/writing-to-a-file-with-xyz-format