On 12/3/13 12:14 PM, 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'?


Regards,
Piotr Dobrogost


I don't know the real reason, but I imagine it would be that it would be very rarely used. It would need to be an attribute that isn't a valid identifier, and you know the attribute at the time you write the code.

I can see scenarios for needing attributes that aren't identifiers, but in many of them you also need to access them through a variable rather than literally.

--Ned.

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to