Python TypeError:必须是不带空字节的字符串,而不是str

Python TypeError:必须是不带空字节的字符串,而不是str,python,null,byte,os.system,Python,Null,Byte,Os.system,我正在尝试运行这段代码,对我拥有的每一帧运行相同的命令(稍作更改): 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

我正在尝试运行这段代码,对我拥有的每一帧运行相同的命令(稍作更改):

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("../")
我运行此命令,得到以下错误:


TypeError回溯(最近一次调用)
在()
7操作系统(comando)
8 pml_cmd=“pymol urei%s.pdb hollow_%s.pdb-c-d”作为卡通,urei%s;颜色为灰色90,urei%s;中心链A;设置视图(\-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.68330955,10.745590210,-568.485290527972.52690918,-20.000000000);bg白色;球形,空心;彩色;空心;蓝色,空心;蓝色,蓝色,蓝色,蓝色,蓝色,蓝色,蓝色,蓝色,蓝色,黑色,黑色,黑色,黑色,黑色,黑色,黑色,黑色,黑色,黑色,黑色,白色,白色,白色,白色,白色,白色,白色,白色,白色,白色,白色,白色,白色,白色,白色,白色,白色,白色,白色,白色,白色,白色,白色
---->9操作系统(pml\U cmd)
10#remove=“rm urei%s.pdb hollow_%s.pdb”%(i,i)
11操作系统(卸下)
TypeError:必须是不带空字节的字符串,而不是str

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

问题在于\char应该是双转义的,即改为“\\” 或者,在字符串偏差前添加一个“r”:

pml_cmd=r“pymol urei%s.pdb…”


由于字符串中的某个位置有一个\0被解释为空字符,因此出现了此特定错误我可以通过注释掉
打印
来解决此错误:

for tarfileobj in inputs:
    # print(tarfileobj)
    tarfileobj.extractall(path=t, members=None)
我可以执行
print(tarfileobj.split)
或打印
repr
或删除
\0
空字节,或者如果是tarfile,就将其解压缩

for tarfileobj in inputs:
    # print(tarfileobj)
    tarfileobj.extractall(path=t, members=None)