anomaly

Terry Reedy tjreedy at udel.edu
Sun May 10 13:09:12 EDT 2015


On 5/10/2015 12:34 PM, Mark Rosenblitt-Janssen wrote:
> Here's something that might be wrong in Python (tried on v2.7):

You are being hypnotized by the fact the 'int' is a builtin name. 
Builtin names are not keywords and can intentionally be rebound.  If you 
rebind randomly, the result may seem strange, but is predictable.  This 
is why be recommend not randomly reusing names of builtins.

>>>> class int(str): pass

This in effect rebinds 'int' to the str class.  The work 'int' no longer 
has any connect to the builtin integer class.

>>>> int(3)

Equivalent to str(3)

> '3'

No surprise that str(3) == '3'.

Replace 'int' with anything else, such as 'zyz' or 'Mark' in both 
statements and the result is the same.

-- 
Terry Jan Reedy




More information about the Python-list mailing list