Python Oddity - print a reserved name

Michael Foord fuzzyman at gmail.com
Wed Sep 15 08:04:01 EDT 2004


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

>>> class thing:
	pass

>>> 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 ?

Regards,

Fuzzy

http://www.voidspace.org.uk/atlantibots/pythonutils.html



More information about the Python-list mailing list