python2:TypeError: must be string without null bytes, not str

Join Stack Overflow to learn, share knowledge, and build your career.

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.

share improve this question
 

2 Answers

The problem is with the \ char that should either be double escaped, i.e. changed to "\\" Or alternatively add an "r" before the string decleration:

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

share improve this answer
 

I was able to resolve this error by commenting out the 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.

share improve this answer
 

Your Answer

 
 
 
 

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged     or ask your own question.

 

转载于:https://www.cnblogs.com/feifeiyuan/p/8431296.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值