Quoted identifiers in Python?

Eddie and Babs kca17 at dial.pipex.com
Thu Mar 29 20:50:34 CEST 2001


Ahem... sorry, I missed the crucial word out there: "__dict__"!
I meant that

    x = obj."Ivor the engine"

...would be the same as:-

    x = obj.__dict__["Ivor the engine"]

The point I was really making was that since the object's attributes are
stored in a dictionary, there is no reason why you shouldn't have any string
you like as the key (you can, after all, do that with any other dictionary).
The ability to use arbitrary strings as attribute names (as opposed to just
the usual alpha-num-underscore characters) DOES have its uses when you are
allowed to re-define the attribute access "dot" operator.


----------
In article <3AC35C84.FBED128 at alcyone.com>, Erik Max Francis
<max at alcyone.com> wrote:


> Eddie and Babs wrote:
>
>> NOW... would this be a good thing for Python to have in the future? It
>> would
>> make element access consistent with subscripting:-
>>
>>         x = obj."Ivor the engine"
>>
>>             ...would be the same as
>>
>>         x = obj["Ivor the engine"]
>>
>> ..no?
>
> I would hope they would not be the same, since one invokes __getattr__
> while the other invokes __getitem__.  They're different things, they
> shouldn't be forced to be the same thing.
>
> --
>  Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
>  __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
> /  \ Traveler, there are no paths.  Paths are made by walking.
> \__/ Antonio Machado
>     REALpolitik / http://www.realpolitik.com/
>  Get your own customized newsfeed online in realtime ... for free!



More information about the Python-list mailing list