0

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 = raw_input("Enter Path:")  
dirList=os.listdir(path)  
csvOut=open('outputnew.csv','w')  
w = csv.writer(csvOut)  
w.writerow(dirList)  
csvOut.close()  

1 Answer 1

2

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...)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.