Python Oddity - print a reserved name

Michael Foord fuzzyman at
Wed Sep 15 14:04:01 CEST 2004

Here's a little oddity with 'print' being a reserved word...

>>> class thing:

>>> something = thing()
>>> something.print = 3
SyntaxError: invalid syntax
>>> print something.__dict__
>>> something.__dict__['print'] = 3
>>> print something.__dict__
{'print': 3}
>>> print something.print
SyntaxError: invalid syntax

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 ?



More information about the Python-list mailing list