Writing to a file with xyz format

馋奶兔 提交于 2019-12-24 12:04:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!