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

Piotr Dobrogost p at google-groups-2013.dobrogost.net
Wed Dec 4 21:35:14 CET 2013


On Wednesday, December 4, 2013 2:06:44 AM UTC+1, Tim Chase wrote:
>
> I think random832 is saying that the designed purpose of setattr()
> was to dynamically set attributes by name, so they could later be
> accessed the traditional way; not designed from the ground-up to
> support non-identifier names.  But because of the getattr/setattr
> machinery (dict key/value pairs), it doesn't prevent you from having
> non-identifiers as names as long as you use only the getattr/setattr
> method of accessing them.

Right. If there's already a way to have attributes with these "non-standard" names (which is a good thing) then for uniformity with dot access to attributes with "standard" names there should be a variant of dot access allowing to access these "non-standard" named attributes, too.

Regards,
Piotr



More information about the Python-list mailing list