字符串转list ,list 转字符串
import string
str = 'abcde'
list = list(str)
list
['a', 'b', 'c', 'd', 'e']
str
'abcde'
str_convert = ''.join(list)
str_convert
'abcde'
#coding: utf-8
import csv
c=open("data.csv","r", encoding="utf-8") #以rb的方式打开csv文件
read=csv.reader(c)
with open('./data1.txt', 'a') as f:
for line in read:
f.write("./train/" + ','.join(line) + '\n')
c.close()
#字符串转list,list转字符串
'''
其中,引号中是字符之间的分割符,如“,”,“;”,“\t”等等
如:
list = [1, 2, 3, 4, 5]
''.join(list) 结果即为:12345
','.join(list) 结果即为:1,2,3,4,5
'''