Why is there no natural syntax for accessing attributes with names not being valid identifiers?

Ethan Furman ethan at stoneleaf.us
Wed Dec 4 16:56:13 CET 2013

On 12/04/2013 03:30 AM, Jussi Piitulainen wrote:
> rusi writes:
>> How do we decide which '-' are valid identifier components --
>> hyphens and which minus-signs?
> I think the OP might be after the JavaScript mechanism where an
> attribute name can be any string, the indexing brackets are always
> available, and the dot notation is available when the attribute name
> looks like a simple identifier. That could be made to work. (I'm not
> saying should, or should not. Just that it seems technically simple.)
> Hm. Can't specific classes be made to behave this way even now by
> implementing suitable underscored methods?

No.  It is possible to provide attribute access along with key access, but not currently possible to provide attribute 
access with quoted values -- which is what the OP wants.


More information about the Python-list mailing list