Stop spaces from appearing when printing to file
Terry Hancock
hancock at anansispaceworks.com
Sun Nov 7 21:12:36 EST 2004
More information about the Python-list mailing list
Sun Nov 7 21:12:36 EST 2004
- Previous message (by thread): Stop spaces from appearing when printing to file
- Next message (by thread): Stop spaces from appearing when printing to file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sunday 07 November 2004 07:02 pm, Brad Tilley wrote: > I'm printing some info into a txt file that will be uploaded into a > MySQL DB. I use ';' as field separaters. How can I stop spaces from > appearing on both sides of the ';' > > When I do this: > > print >> x,';',object,";",AN_string,";",ascii,";",sum > > My file looks like this: > > ;12345 ; 23456 ; [1,2,3,4,5] ; 15 > > I need it to look like this to make the DB happy: > > ;12345;23456;[1,2,3,4,5];15 Generally speaking, you'll be better off to produce the string you want and then print it, rather than relying on the print command's syntax. You'll find it much more intuitive to do either: print x+';'+object+";"+AN_string+";"+ascii+";"+sum or print "%s;%s;%s;%s;%s" % (x, object, AN_string, ascii, sum) In other words, use string operators, then print the result. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com
- Previous message (by thread): Stop spaces from appearing when printing to file
- Next message (by thread): Stop spaces from appearing when printing to file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list