开发者

Python csv write module, need output into different rows instead of columns

I am trying to get a list of files for a certain path in a csv file. I get the desired results but they are in a single row. How can the output appear in different rows.

My code is follows:

import csv  
import os  
path = 开发者_如何学Pythonraw_input("Enter Path:")  
dirList=os.listdir(path)  
csvOut=open('outputnew.csv','w')  
w = csv.writer(csvOut)  
w.writerow(dirList)  
csvOut.close()  


Call writerow multiple times to put the list into different rows.

for directory in dirList:
    w.writerow([directory])

(But in this case I don't see the need of using CSV...)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜