anomaly

boB Stepp robertvstepp at gmail.com
Sun May 10 15:12:44 EDT 2015


I am in process learning Python and normally hang out on the Tutor
list, but monitor this one hoping to learn what I can. This thread is
of interest to me from the standpoint of trying to understand the
Python way of doing things.

On Sun, May 10, 2015 at 12:28 PM, Gary Herron <gherron at digipen.edu> wrote:
> On 05/10/2015 09:48 AM, Rustom Mody wrote:
>>
>> On Sunday, May 10, 2015 at 10:14:36 PM UTC+5:30, Ian wrote:
>>>
>>> On Sun, May 10, 2015 at 10:34 AM, Mark Rosenblitt-Janssen wrote:
>>>>
>>>> Here's something that might be wrong in Python (tried on v2.7):
>>>>
>>>>>>> class int(str): pass
>>>
>>> This defines a new class named "int" that is a subclass of str. It has
>>> no relation to the builtin class int.
>>>
>>>>>>> int(3)
>>>>
>>>> '3'
>>>
>>> This creates an instance of the above "int" class, which is basically
>>> equivalent to calling "str(3)".
>>>
>>> Were you expecting a different result?
>>
>> In C (family) languages int is a keyword
>>  From that pov this is completely bizarre
>
>
> Not really.  Expecting Python to act like C family languages *is* bizarre.

I have to admit being surprised by this, too. I am just now studying
on how to write my own classes in Python, and have come to realize
that doing this is *possible*, but the *surprise* to me is why the
language design allowed this to actually be done.

> Common Python thought::  "We're all adults here."    If you want to override
> a builtin within your own namespace, who are we to stop you?

I'm surprised that this thought has not been added to the "Zen Of
Python", as I see it as more and more recurrent as I continue my
studies. What I would like to comprehend is what is the essential
mindset of Python? That is, what do I need to understand, so that I am
no longer likely to be surprised by discovering new possibilities in
Python such as what the current thread is discussing?


-- 
boB



More information about the Python-list mailing list