Home > Net >  Python some strings to list
Python some strings to list

Time:04-12

let's assume that program take these variables;

website = "https://stackoverflow.com/questions/"
username = "BestSithInEU"
password = "S0n'X%`2FU`,t!j-" 

My aim that, I want to store these datas with another class;

class forExample:
    self.header = ["website", "username / email", "password"]
    self.data_list = [website, username, password]

    ### And I'm using this method from csv library
    with open("password.csv", "a", encoding="UTF8", newline="") as f:
        writer = csv.writer(f)

        write multiple rows
        writer.writerows(self.data_list)

How can I convert these three variables to list of strings? And also when I use this self.data_list I'm getting this output...

website username/email password
h,t,t,p,s,:,/,/,s,t,a,c,k,o,v,e,r,f,l,o,w,.,c,o,m,/,q,u,e,s,t,i,o,n,s,/
B,e,s,t,S,i,t,h,I,n,E,U

_csv.Error: iterable expected, not NoneType

CodePudding user response:

The csv writer expects a list of lists. So

self.data_list = [ [website, username, password] ]

  • Related