PEP 214 - Why not print >> string?
Aaron Swartz
me at aaronsw.com
Thu Jan 10 21:57:32 EST 2002
On 2002-10-01 1:08 PM, in article yu99d70it45b.fsf at europa.research.att.com,
"Andrew Koenig" <ark at research.att.com> wrote:
> So
> x = ''
> print >> x, 3
> print >> x, 3
>
> would cause x to be '3 3'? Or would it be '3\n3\n' ?
The latter, as the normal print rules will apply (of course the \ns could be
suppressed by a trailing ',').
> What if I forgot to say x = '' first?
The same thing that happens now, namely:
>>> print >> foo, a
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'foo' is not defined
Or
>>> x = 2
>>> print >> x, 'a'
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'int' object has no attribute 'write'
(perhaps a better error could be given, but the idea is the same)
--
[ "Aaron Swartz" ; <mailto:me at aaronsw.com> ; <http://www.aaronsw.com/> ]
More information about the Python-list
mailing list