![](/img/trans.png)
[英]TypeError: file() argument 1 must be encoded string without NULL bytes, not str
[英]TypeError: must be string without null bytes, not 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
我在互聯網上搜索,但找不到很好的答案。
問題在於\\ char應該被兩次轉義,即更改為“ \\\\”,或者在字符串解串之前添加“ r”:
pml_cmd = r“ pymol urei%s.pdb ...”
您會收到此特定錯誤,因為在字符串的某處有一個\\ 0,它被解釋為NULL字符
我可以通過注釋掉print
來解決此錯誤:
for tarfileobj in inputs:
# print(tarfileobj)
tarfileobj.extractall(path=t, members=None)
我可以完成print(tarfileobj.split)
或打印repr
或刪除\\0
空字節,或者如果它是tarfile,只需將其解壓縮即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.