最近写脚本的时候,发现了python2的一个bug
>>>a='accepted_hits.bam'
>>> a.rstrip('.bam')
'accepted_hits'
这个很正常
>>> pre='accepted_hits'
>>> a='%s.sam'%pre
>>> a.rstrip('.sam')
'accepted_hit'
accepted_hits 变成了 accepted_hit
>>> print(pre)
accepted_hits
>>> print(a)
accepted_hits.sam
>>> a.rstrip('.sam')
'accepted_hit'
确实是一个bug,可能是这个地方程序有bug:a=’%s.sam’%pre,pre=‘accepted_hits’使得pre的最后一位为’s’,将最后一位换成其他字符就正常了。
>>> pre='accepted_hitq'
>>> a='%s.sam'%pre
>>> a
'accepted_hitq.sam'
>>> a.rstrip('.sam')
'accepted_hitq'