简体   繁体   English

TypeError:必须是不包含空字节的字符串,而不是str

[英]TypeError: must be string without null bytes, not 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. 我在互联网上搜索,但找不到很好的答案。

The problem is with the \\ char that should either be double escaped, ie changed to "\\\\" Or alternatively add an "r" before the string decleration: 问题在于\\ char应该被两次转义,即更改为“ \\\\”,或者在字符串解串之前添加“ r”:

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

You get this particular error since somewhere along the string there is a \\0 which is interpreted as a NULL char 您会收到此特定错误,因为在字符串的某处有一个\\ 0,它被解释为NULL字符

I was able to resolve this error by commenting out the print : 我可以通过注释掉print来解决此错误:

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

I could have done print(tarfileobj.split) or printed the repr or removed \\0 null bytes, or if its a tarfile, just extract it. 我可以完成print(tarfileobj.split)或打印repr或删除\\0空字节,或者如果它是tarfile,只需将其解压缩即可。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:file()参数1必须是没有NULL字节的编码字符串,而不是str - TypeError: file() argument 1 must be encoded string without NULL bytes, not str TypeError:必须是不包含空字节的字符串,在os.system()中不能为str - TypeError: must be string without null bytes, not str in os.system() python TypeError:必须是没有 NULL 字节的编码字符串,而不是 str - docker iron requirements.txt - python TypeError: must be encoded string without NULL bytes, not str - docker iron requirements.txt 训练 &#39;\\x00&#39; s 和 TypeError: stat() 参数 1 必须是没有空字节的编码字符串,而不是 str - Training '\x00' s and TypeError: stat() argument 1 must be encoded string without null bytes, not str TypeError:必须为str,而不是字节 - TypeError: must be str, not bytes “必须是没有 null 字节的字符串”或“无法将 str 连接到字节”在命令行上传递有效负载 - “must be a string without null bytes” or “can't concat str to bytes” passing a payload on a command line TypeError:必须是str,而不是字节Error - TypeError: must be str, not bytes Error 在 Python3 中解码字节字符串时出错 [TypeError: must be str, not bytes] - Error decoding byte string in Python3 [TypeError: must be str, not bytes] TypeError:compile()期望字符串,不带空字节 - TypeError: compile() expected string without null bytes 类型错误:JSON 对象必须是 str,而不是 &#39;bytes&#39; - TypeError: the JSON object must be str, not 'bytes'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM