我有一个特定的检查要完成,如果检查满足,我想要打印结果。下面是代码:
import string
import codecs
import sys
y=sys.argv[1]
list_1=[]
f=1.0
x=0.05
write_in = open ("new_file.txt", "w")
write_in_1 = open ("new_file_1.txt", "w")
ligand_file=open( y, "r" ) #Open the receptor.txt file
ligand_lines=ligand_file.readlines() # Read all the lines into the array
ligand_lines=map( string.strip, ligand_lines ) #Remove the newline character from all the pdb file names
ligand_file.close()
ligand_file=open( "unique_count_c_from_ac.txt", "r" ) #Open the receptor.txt file
ligand_lines_1=ligand_file.readlines() # Read all the lines into the array
ligand_lines_1=map( string.strip, ligand_lines_1 ) #Remove the newline character from all the pdb file names
ligand_file.close()
s=[]
for i in ligand_lines:
for j in ligand_lines_1:
j = j.split()
if i == j[1]:
print j
上面的代码效果很好,但是当我打印 j 时,它打印成 ['351', '342'] 但我期望得到 351 342(中间有一个空格)。由于它更像是一个 python 问题,我没有包含输入文件(基本上它们只是数字)。
谁能帮帮我?
干杯,
查瓦纳克
请您参考如下方法:
要将字符串列表转换为列表项之间有空格的单个字符串,请使用 ' '.join(seq) .
>>> ' '.join(['1','2','3'])
'1 2 3'
您可以在项目之间用您想要的任何字符串替换 ' '。
