Python Oddity - print a reserved name

Peter Otten __peter__ at web.de
Wed Sep 15 08:37:49 EDT 2004


Michael Foord wrote:

> See that I can't set the something.print attribute directly, but can
> set it indirectly. Is this behaviour 'necessary' or just an anomaly of
> the way IDLE detects Syntax Errors ?

I'd say checking at runtime whether attribute names are valid costs too much
performance, so it's not done. Another nice example (on the interactive
prompt, this has nothing to do with idle):

>>> class X:
...     pass
...
>>> x = X()
>>> setattr(x, "!@~%", 42)
>>> dir(x)
['!@~%', '__doc__', '__module__']

:-)

Peter






More information about the Python-list mailing list