print to file

Colin J. Williams cjw at sympatico.ca
Sun Nov 24 12:10:55 EST 2002


David Mertz wrote:
[snip]

>
> I think--as Alex does--that the "print >> FILE" form was a mistake.  But
> it is just ugly syntax, and I've even found myself using it
> occassionally.
>

[snip]
I had not come across this before and so I gave it a try:
>>> print 'abc' >> file('ugh.py', 'w')
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: unsupported operand type(s) for >>: 'str' and 'file'
>>> f=file('ugh.py', 'w')
>>> print 'abc' >> f
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: unsupported operand type(s) for >>: 'str' and 'file'
>>>
Am I misinterpreting Section 6.6 of the language doc?

I get a similar result with Python or PythonWin.

Colin W.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20021124/b80aada4/attachment.html>


More information about the Python-list mailing list