Re: Result of ``a is b''
On 18-mrt-04, at 14:14, Axel Boldt wrote:
[color=blue]
> afriere@yahoo.c o.uk (Asun Friere) wrote[color=green]
>> axelboldt@yahoo .com (Axel Boldt) wrote[/color]
>[color=green][color=darkred]
>>> Why would anybody ever want to
>>> know whether two strings or tupels are internally stored at the same
>>> location, other than to deduce details of the Python implementation?[/color]
>>
>> Most obviously to tell whether they are the same object or not.
>> While this is not an issue with simple strings, have you considered
>> what effect your suggestions would have on classes inheriting from
>> str?[/color]
>
> Indeed I have not. Probably because basic built-in strings form a type
> that's not a class and you can't inherit from it.[/color]
Yes you can:
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
>>> class MyStr(str): pass[/color][/color][/color]
....[color=blue][color=green][color=darkred]
>>> x = MyStr("hello")
>>> type(x)[/color][/color][/color]
<class '__main__.MyStr '>[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
On 18-mrt-04, at 14:14, Axel Boldt wrote:
[color=blue]
> afriere@yahoo.c o.uk (Asun Friere) wrote[color=green]
>> axelboldt@yahoo .com (Axel Boldt) wrote[/color]
>[color=green][color=darkred]
>>> Why would anybody ever want to
>>> know whether two strings or tupels are internally stored at the same
>>> location, other than to deduce details of the Python implementation?[/color]
>>
>> Most obviously to tell whether they are the same object or not.
>> While this is not an issue with simple strings, have you considered
>> what effect your suggestions would have on classes inheriting from
>> str?[/color]
>
> Indeed I have not. Probably because basic built-in strings form a type
> that's not a class and you can't inherit from it.[/color]
Yes you can:
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
>>> class MyStr(str): pass[/color][/color][/color]
....[color=blue][color=green][color=darkred]
>>> x = MyStr("hello")
>>> type(x)[/color][/color][/color]
<class '__main__.MyStr '>[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
Comment