Python 3.3 Writing A String From A List To A txt File -


i trying write string list text file on new lines

the string stored in list follows

name:emailaddress:mobilenumber

i have repr in class prints out readable string screen if user wants print contacts screen print follows:

name - email address - mobile number

i can write text file name - email address - mobile number

but want write text file follows:

name email address mobile number 

i'm not sure how strip out "-"

the code have far follows:

file = open("staffdata.txt", "w") contacts in stafflist :    file.write(str(contacts) + "\n") file.close() 

any guidance me appreciated

if understood correctly, like:

with open("staffdata.txt", "wt") file:     contacts in stafflist :        file.write("\n".join(str(contacts).split(' - ')) + "\n") 

edit: according last question update, every field goes in different line


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -