removing characters before writing to file
Peter Otten
__peter__ at web.de
Thu Feb 9 08:02:51 EST 2006
More information about the Python-list mailing list
Thu Feb 9 08:02:51 EST 2006
- Previous message (by thread): how to remove <BR> using replace function?
- Next message (by thread): removing characters before writing to file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
eight02645999 at yahoo.com wrote: > i have some output that returns a lines of tuples eg > > ('sometext1', 1421248118, 1, 'P ') > ('sometext2', 1421248338, 2, 'S ') > and so on > .... > > I tried this > re.sub(r" '() ",'',str(output)) but it only get rid of the ' and not > the braces. I need to write the output to a file such that > > sometext1, 1421248118, 1, P > sometext2, 1421248338, 2, S > > I also tried escaping , re.sub(r" '\(\) ",'',str(output)) but also did > not work > How can i get rid of the braces before writing to file? thanks I'd use a csv.writer: >>> import csv, sys >>> data = [ ... ('sometext1', 1421248118, 1, 'P '), ... ('sometext2', 1421248338, 2, 'S ') ... ] >>> w = csv.writer(sys.stdout) >>> w.writerows(data) sometext1,1421248118,1,P sometext2,1421248338,2,S Peter
- Previous message (by thread): how to remove <BR> using replace function?
- Next message (by thread): removing characters before writing to file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list