"Write to a file" question please?

Olivier Dagenais olivierS.dagenaisP at canadaA.comM
Wed Jul 5 09:43:16 EDT 2000


Make this adjustement:

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

I just tried it, and it works.  My guess is the rules for write are
different than for print, so what appears to be a string concatenation in
print might just be a sequence type of some sort.  (sorry, I learned Python
this weekend, that's the best I can do in explaining it)

You can also use:

OUT.write ("Number =" + str(number))

...which might be more what you're looking for.

--
----------------------------------------------------------------------
Olivier A. Dagenais - Carleton University - Computer Science III


<cmfinlay at SPAMmagnet.com.au> wrote in message
news:tzFjOfN2zOzPHwvl3ncklEAEb+fa at 4ax.com...
> 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.
>
> Any help would be much appreciated
> E-mail me at cmfinlaySPAM at magnet.com.au
> or reply here.





More information about the Python-list mailing list