Python 输出未获取字符串+;整数

Python 输出未获取字符串+;整数,python,python-2.7,Python,Python 2.7,我得到的结果如下: #!/usr/bin/env python import os,subprocess,re f=open("/var/tmp/disks_out","w") proc=subprocess.Popen(['df', '-h'],stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=False) out,err=proc.communicate() for line in out: f.write(line) f.clos

我得到的结果如下:

#!/usr/bin/env python
import os,subprocess,re
f=open("/var/tmp/disks_out","w")
proc=subprocess.Popen(['df', '-h'],stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=False)
out,err=proc.communicate()
for line in out:
   f.write(line)
f.close()
f1=open("/var/tmp/disks_out","r")
disks=[]
for line in f1:
    m=re.search(r'(c.*s0)',line)
    if m:
      disk=m.group(1)
disks.append(disk)
disks = disks[0][:-1]
slices =[disks+i for i in str(range(5))]
print(slices)
但我也希望得到类似的输出:

['c0t5000CCA025A29894d0s0', 'c0t5000CCA025A29894d0s1', 'c0t5000CCA025A29894d0s3', 'c0t5000CCA025A29894d0s4', 'c0t50                                                                                                                          00CCA025A29894d0s5', 'c0t5000CCA025A29894d0s6']

如果要用逗号表示,请执行以下操作:

c0t5000CCA025A29894d0s1,c0t5000CCA025A29894d0s2,c0t5000CCA025A29894d0s3
或者更确切地说,对于python 2.7:

print(','.join(slices))

您打印出来的是列表,所以python将其解释为一个
join()
method通过传递的字符串连接iterable的每个元素,更多信息(对于放入标记中的Python 2.7),但这里似乎使用的是Python 3。

是否希望输出为字符串?如果是,则打印“,”。加入(切片)
print ','.join(slices)