Stop spaces from appearing when printing to file
kent3737 at yahoo.com
Mon Nov 8 02:25:04 CET 2004
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 ';'
The spaces are a feature of print. To avoid them, use string formatting
to create a single output string.
> print >> x,';',object,";",AN_string,";",ascii,";",sum
print >> x, ';%s;%s;%s;%s' % (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:
More information about the Python-list