Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 2

writing the output results on CSV file, python

I reached below list (data list in the end code) after calculation of the hash password from the csv file:

['danial', 5104, 'elham', 9770]

and i am going to write every name and password on csv file (update it) in below order:

 

danial,5104
elham,9770

 

I have used below code, but the output is false.

data=[]
for item in list3:
    #data=[]
    l3=[]
    l3.append(item)
    #print(l3)
    data.append(str(item))
print(data)

with open('code.csv', 'w', newline='') as output_file_name:
        writer = csv.writer(output_file_name)
        writer.writerows(data)
        output_file_name.close()
 
1 Reply
Highlighted
Commander Lvl 1
Message 2 of 2

Re: writing the output results on CSV file, python

Each row needs to be a separate list. I.e. your data field currently looks like:

['danial', '5104', 'elham', '9770']

and to get it to output in your desired format, needs to look like:

[ [ 'danial', '5104' ], [ 'elham', '9770' ] ]

(extra spaces for readability).

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!