Stop spaces from appearing when printing to file
Scott David Daniels
Scott.Daniels at Acm.Org
Sun Nov 7 20:43:18 EST 2004
Kent Johnson wrote:
> 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
>
>
> Try
> print >> x, ';%s;%s;%s;%s' % (object, AN_string, ascii, sum)
or even:
print >>x, ';'.join([str(v) for v in (object, AN_string, ascii, sum)])
-Scott David Daniels
Scott.DanielsAcm.Org
More information about the Python-list
mailing list