"Write to a file" question please?

Norman Vine nhv at cape.com
Wed Jul 5 10:38:53 EDT 2000


<cmfinlay at SPAMmagnet.com.au>

> number = 100
> print "Number =", number
> OUT = open("TT.txt","w")
> OUT.write("Number =", number) # Error
> OUT.close()
>
> The code above gives the error.
>
> Traceback (innermost last):
>   File "ttest.py", line 5, in ?
>     OUT.write("Number =", number)
> TypeError: read-only buffer, tuple
>
> OUT.write("Hello World")
>
> Works but a number or variable of a number does not.
>
> I have been reading documents on Python to no avail this time.
> I am using Win98 with the latest python for this OS.
>

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

see
Python\Doc\tut\formatting.html

Norman





More information about the Python-list mailing list