Re: [Tutor] How to print to a file?

Magnus Lycka magnus at thinkware.se
Thu Feb 19 03:42:30 EST 2004


denny wrote:
> I want to write something to a file like this:
> print >>filehandle, "....%d...%s..."%(num,string)
> but it raise error

If you have opened "filehandle" for writing, and have
correct content in the variables "num" and "string",
the code above works. As Karl suggested, it's a good 
idea to include exact error messages in your questions.

>>> filehandle = file('c:/tmp.txt', 'w')
>>> num,string = 3, 'Hello'
>>> print >>filehandle, "....%d...%s..."%(num,string)

>>> filehandle.close()
>>> print file('c:/tmp.txt').read()
...3...Hello...

>>> 


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus at thinkware.se



More information about the Tutor mailing list