Lillian Jiang
09/08/2025, 1:29 PMkapa.ai
09/08/2025, 1:29 PMJustin Beasley
09/08/2025, 1:44 PMImplementation note in that section), the dot notation and subscript access ([]) check the same things, but in a different order:
• Dot Notation: checks for an attribute first (getattr), then an item (__getitem__)
• Subscript Access: checks for an item first (__getitem__), then an attribute (getattr)
So whenever a variable has both an item and an attribute with the same name, these two syntaxes will return different results.
. . . which can be very confusing.
There's no good fix, other than to know this is possible. And in cases where you're producing the objects or know their attribute and item names, you also know how to predict which will win for a given syntax. But when this is coming from a component or such, you may be surprised when it doesn't work and need to try the other method. 🙃Lillian Jiang
09/08/2025, 1:45 PMgetattr and __getitem__ of an object so we know which one to call beforehand?Justin Beasley
09/08/2025, 1:56 PMname where sometimes there's already some attribute that might be different than the item).
Generally I agree with the docs though—use . when you can, unless you know there's an attribute of the same name when you actually want the itemLillian Jiang
09/08/2025, 2:00 PM