Why is there no natural syntax for accessing attributes with names not being valid identifiers?
breamoreboy at yahoo.co.uk
Wed Dec 4 21:46:26 CET 2013
On 04/12/2013 20:35, Piotr Dobrogost wrote:
> 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.
The obvious thing to do is to either raise this on python ideas, or if
you're that confident about it raise an issue on the bug tracker with a
patch, which would include changes to unit tests and documentation as
well as code, get it reviewed and approved and Bob's your uncle, job
done. Too late for Python 3.4 of course, but no problem for 3.5.
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
More information about the Python-list