我可以使用Python在.txt中打印一行,比如“[aln-core]:10000000序列已被处理”
但我想打印数字(10000000,这是我想要的信息);我怎样才能做到这一点/ THX
答案 0 :(得分:2)
一个简单的解决方案:
line = '[aln-core]:10000000 sequences have been processed'
line = ''.join(c for c in line if c.isdigit())
正则表达式解决方案:
import re
line = '[aln-core]:10000000 sequences have been processed'
print re.search('\d+', line).group()
答案 1 :(得分:2)
你的意思是你想从一些行中得到10000000 =“[aln-core]:已经处理了10000000个序列”?
如果您确定该行始终如此,请尝试
line.split(':')[1].split[0]
我的意思是......
line = "[aln-core]:10000000 sequences have been processed"
line.split(':')[1]
'10000000 sequences have been processed'
line.split(':')[1].split()[0]
'10000000'