"Write to a file" question please?

Paul Jensen usenet at foreignkey.com
Wed Jul 5 10:32:57 EDT 2000


cmfinlay at SPAMmagnet.com.au writes:

> number = 100
> print "Number =", number
> OUT = open("TT.txt","w")
> OUT.write("Number =", number) # Error
> OUT.close()

The problem is that 'print' is a statement, but the write() function
wants an expression, so you use the "%" operator to substitute values
into the string printf() style, like:

		OUT.write("Number = %d" % number)

I wanted to include a reference to the "%" operator in the online
docs, but interestingly couldn't find one. Anyone know offhand where
"%" is covered in the docs?

Cheers,
-- 
Paul Jensen <usenet at foreignkey.com>



More information about the Python-list mailing list