【问题标题】:TypeError: must be string without null bytes, not strTypeError:必须是没有空字节的字符串,而不是 str
【发布时间】:2013-08-16 02:51:07
【问题描述】:

我正在尝试运行此代码,以对我拥有的每一帧运行相同的命令(几乎没有更改):

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                                 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

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

【问题讨论】:

    标签: python null byte os.system


    【解决方案1】:

    问题在于应该双转义的 \ 字符,即更改为“\\” 或者在字符串声明之前添加一个“r”:

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

    你会得到这个特殊的错误,因为在字符串的某个地方有一个 \0,它被解释为一个 NULL 字符

    【讨论】:

      【解决方案2】:

      我可以通过注释掉print来解决这个错误:

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

      我可以完成 print(tarfileobj.split) 或打印 repr 或删除 \0 空字节,或者如果它是一个 tar 文件,只需解压缩它。

      【讨论】:

        猜你喜欢
        • 2012-09-17
        • 1970-01-01
        • 2016-04-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-13
        • 2020-12-03
        相关资源
        最近更新 更多