TypeError:必须是不包含空字节的字符串,而不是str [英] TypeError: must be string without null bytes, not str

查看:127
本文介绍了TypeError:必须是不包含空字节的字符串,而不是str的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行此代码,以便在我拥有的每个帧中运行相同的命令(几乎没有变化):

I'm trying to run this code, to run the same command (with little changes) with every frame that I have:

traj.reset()
import os
#os.chdir(outname)
for i, frame in enumerate(traj):
    frame.superpose()
    comando = "python hollow.py -c constraint -o hollow_%s.pdb urei%s.pdb" % (i, i)
    os.system(comando)
    pml_cmd = "pymol urei%s.pdb hollow_%s.pdb -c -d 'as cartoon, urei%s;color gray90, urei%s;center chain A;set_view (\-0.605158150,0.089404292,0.791067421,\0.795849979,0.093013920,0.598304033,\-0.020089993,0.991641700,-0.127439827,\0.000000000,0.000000000,-202.017959595,\-28.771762848,-7.683309555,10.745590210,\-568.485290527,972.520690918,-20.000000000);bg white;as sphere, hollow_%s;color cyan, hollow_%s;ray;save urei%s.png' " % (i, i, i, i, i, i, i)
    os.system(pml_cmd)
    #remove = "rm urei%s.pdb hollow_%s.pdb" % (i, i)
    #os.system(remove)
os.chdir("../")

我运行了这个错误消息:

I run this and I get this error:

TypeError                                 Traceback (most recent call last)
<ipython-input-8-53cd3e7bd107> in <module>()
      7     os.system(comando)
          8     pml_cmd = "pymol urei%s.pdb hollow_%s.pdb -c -d 'as cartoon, urei%s;color gray90, urei%s;center chain A;set_view (\-0.605158150,0.089404292,0.791067421,\0.795849979,0.093013920,0.598304033,\-0.020089993,0.991641700,-0.127439827,\0.000000000,0.000000000,-202.017959595,\-28.771762848,-7.683309555,10.745590210,\-568.485290527,972.520690918,-20.000000000);bg white;as sphere, hollow_%s;color cyan, hollow_%s;ray;save urei%s.png' " % (i, i, i, i, i, i, i)
----> 9     os.system(pml_cmd)
     10     #remove = "rm urei%s.pdb hollow_%s.pdb" % (i, i)
     11     #os.system(remove)

TypeError: must be string without null bytes, not str

我在互联网上搜索过,但是我找不到很好的答案。

I searched in internet, but I can't find a good answer.

推荐答案

问题在于\ char应该是双转义的,即更改为 \\
或在字符串解串之前添加 r:

The problem is with the \ char that should either be double escaped, i.e. changed to "\\" Or alternatively add an "r" before the string decleration:

pml_cmd = r pymol urei%s.pdb。 ..

pml_cmd = r"pymol urei%s.pdb ..."

由于字符串中某处有一个along0,它被解释为NULL char

You get this particular error since somewhere along the string there is a \0 which is interpreted as a NULL char

这篇关于TypeError:必须是不包含空字节的字符串,而不是str的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆