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

random832 at fastmail.us random832 at fastmail.us
Tue Dec 3 19:03:41 CET 2013

On Tue, Dec 3, 2013, at 12:14, Piotr Dobrogost wrote:
> Hi!
> I find global getattr() function awkward when reading code.
> What is the reason there's no "natural" syntax allowing to access
> attributes with names not being valid Python identifiers in a similar way
> to other attributes?
> Something along the line of
> my_object.'valid-attribute-name-but-not-valid-identifier'?

The getattr function is meant for when your attribute name is in a
variable. Being able to use strings that aren't valid identifiers is a
side effect. Why are you designing classes with attributes that aren't
valid identifiers?

More information about the Python-list mailing list