Stop spaces from appearing when printing to file

Dave Reed drlinux at columbus.rr.com
Sun Nov 7 20:39:04 EST 2004


On Sunday 07 November 2004 20:02, 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


Instead of using print, open a file and use the "write" method of the
file object. See the documentation for file objects for more detail.

Dave





More information about the Python-list mailing list