def append(new)
user_file = open(r'users.csv', "a", newline = '')
writer = csv.writer(user_file)
writer.writerows(new)
#create a user list[... , ...]
append(user)
I tried to append rows in CSV file, and I can have the correct data in my list. However, the data in my CSV file has something wrong.
My original contents in CSV file:
admin, abcd
user1, qwer
I expect that my CSV file after running should like this:
admin, abcd
user1, qwer
appenduser, appendpassword
However, after running my program, my CSV file append like this:
admin, abcd
user1, qwer
a,p,p,e,n,d,u,s,e,r
a,p,p,e,n,d,p,a,s,s,w,o,r,d
What should I do in order to solve my problem? Appreciate for helps!
Use writerow
Ex:
def append(new):
user_file = open(r'users.csv', "a", newline = '')
writer = csv.writer(user_file)
writer.writerow(new)
#create a user list[... , ...]
append(user)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.