【发布时间】:2015-07-18 04:57:41
【问题描述】:
我有一个路径名列表:
li = [u"C:\\temp\\fileA.shp", u"C:\\temp\\fileB.shp", u"C:\\temp\\fileC.shp"]
我正在尝试将每个路径写入 txt 文件中的单独一行。这是我到目前为止所做的:
import csv
li = [u"C:\\temp\\fileA.shp", u"C:\\temp\\fileB.shp", u"C:\\temp\\fileC.shp"]
with open(r'C:\temp\myfile.csv', "wb") as f:
wr = csv.writer(f, delimiter=',', quoting=csv.QUOTE_NONE)
wr.writerows([li])
这会产生同一行的文件列表:
C:\temp\fileA.shp,C:\temp\fileB.shp,C:\temp\fileC.shp
我怎样才能调整它,使路径名都在自己的行上?以下是我所追求的:
C:\temp\fileA.shp
C:\temp\fileB.shp
C:\temp\fileC.shp
【问题讨论】:
-
链接的问题有你的问题的答案。如果直接写入txt文件,则不需要使用CSV。