2013-08-16 108 views
7

我試圖運行此代碼,運行相同的命令(小變化),每幀我有:類型錯誤:必須是字符串,不空字節,而不是str的

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 

我搜索互聯網,但我不能找到一個很好的答案。

回答

3

的問題是與應該要麼雙逃過\炭,即改變爲「\\」 或可替代地添加一個「R」的字符串decleration之前:

pml_cmd = R「PyMOL的UREI%S .PDB ......」

因爲某處沿串有一個\ 0,這被解釋爲NULL字符的時候得到這個特殊的錯誤

0

我能夠通過註釋掉print解決此錯誤:

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

我本來可以做print(tarfileobj.split)或打印repr或刪除\0空字節,或者如果它的tarfile,只是提取它。

相關問題