打開CSV文件寫入另一個CSV

 字符串轉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

'''

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章