写入一个xyz格式的文件 [英] Writing to a file with xyz format
问题描述
我想用xyz格式在轨迹文件中写x点和y点。但我是一个Python初学者,并且这段代码给出错误行续行字符
后的意外字符。第一行是原子数,第二行是注释,第三行是坐标。
xyz.close()
$ b $问题是这一行,与字符 \
(python可能认为是一条线在某些情况下延续性)。当你解决这个问题的时候,你也会遇到%8x
和%8z
是非法格式化字符的问题。我不知道你想要什么,但是%s
可能工作。
为了解决这两个问题,改变这个:
xyz.write('%s,%8x,%8y,%8z'\\'n%( xpoints,ypoints,0)')
对此:
xyz.write('%s,%8s,%8s,%8s\''(xpoints,ypoints,0))
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()
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))
这篇关于写入一个xyz格式的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!