The term 'dot-notation' as used in Python seems to be used for two groups of meanings in Python:

1) most are JavaScript/JSON-inspired coding practices (e.g. expectations that nested object or dict references to undefined (chains of) keys should automatically recursively create all the object attributes/dict keys in the chain, in the manner of defaultdict/autovivification) ...

2) whereas some other mentions are simply "when/should I call a method on an object vs referencing it via attributes, or via a property". Conversely these are existing builtin Python language syntax.

[EDIT: per @jpp's answer, I'm not proposing inventorying all the individual places 'dot notation' is used for builtin Python syntax. Just separating meaning 2) as a group from meaning 1)]

What seems to be lost on non-Python programmers is that meaning 1) of "[implementing] dot notation" in Python is largely a foreign thing which the language does not natively implement (yet is well-defined in JS), so unlike JS we have to implement it piecewise ourselves, and that requires that we're clear what the defined behavior(s) are.

Some questions are only about objects, some only about dicts, some about both, some about the difference between the two. Some are only about old-style/2.x objects and have been obviated by 3.x

Some questions are about namespaces

Some questions are about loading/dumping JSON at the same time or in the same code as getting/setting the multiply-nested dicts or objects

Some uses ignore or break inheritance e.g. by messing with __getattribute__ or not calling super.

Moreover, doing this across 3.x and 2.x, and in a performant way, and using builtins where possible, are all considerations.

So the question is: How can we define and organize the main distinct meanings of 'dot-notation' in Python? and aggregate questions on the first meaning, which is "JS-style automatic getting/setting of nested chains of object attributes/dict keys(/namespaces)". ** Following are some questions **not to endorse their propositions, just to illustrate that this topic is swimming in duplicates, as a motivation why we should clean this up:

Is there any reason to not just use the search tools to find what you want to find?
– BraiamJan 7 at 15:38

3

@Braiam: why are you talking down to me? a) SO's search function is universally acknowledged to be broken b) That's before you get to "dot notation" is not well-defined in Python (although it should be, which is the motivation here) c) I am none of those OPs d) however most of the questions asked are reasonable e) yet there are tons of duplicates of near-duplicates f) and since they weren't ever properly merged, we get garbled answers on this issue going back to 2010 and earlier g) So even if we hypothesize there was a perfect search function, which there isn't, there's still work to be done..
– smciJan 7 at 15:45

2

...identifying which of these Q&A is canonical and has good answers on 3.x, improving and tagging the canonical ones, and closing all the others as duplicates. So, please join in.
– smciJan 7 at 15:46

1

I was recently working with recursive dicts/defaultdicts. It took me a while to realize that most Python users mentioning "dot notation" in this context simply want JS-style automatic get/set of hierarchies of dict keys and/or object attributes. And that most answers on this are reinventing the wheel. Except for the ones which break inheritance, reach directly into self.__dict__ (instead of via getattr) or reduce performance, which are plain bad, and should be closed/merged explaining why they're bad. Figuring all that out took me time, and search function won't fix any of that.
– smciJan 7 at 16:04

For the couple of people who are downvoting, please make your own suggestions about what if anything can be improved on this topic. Even if you personally don't care that this topic is currently a garbled mess with stale and broken code going back to 2010, it prevents it being a reusable resource for other users.
– smciJan 7 at 16:05

2

@smci: "How can we define and organize all these distinct meanings of 'dot-notation' in Python?" I'm not a Python user, so I don't fully understand the technical details of it. But why exactly does SO need to do this? What would be improved by having some definition of a concept that Python itself doesn't define? And how would we enforce such a definition?
– Nicol BolasJan 7 at 17:07

@NicolBolas: already addressed above, but the main meaning (in Python) is "JS-style automatic get/set of hierarchies of dict keys and/or object attributes", for which we need to identify canonical targets, merge, then close all the bad/duplicate reaskings. Like I said there is a lot of old 2.x cruft which breaks inheritance or reduces performance, that stuff needs to be closed badly. Conversely for the other meanings (i.e. various places in the existing language syntax where Python uses a '.'), I wasn't suggesting inventorying all of them, per jpp's list. Just disambiguating the first sense
– smciJan 8 at 5:09

@NicolBolas: to give a more clear concise answer on the "Why do we need to [in SO Python]?", I revised this to say "separating meaning 2) (various uses in builtin syntax) as a group from meaning 1) (implementing JS-style)". I wasn't suggesting inventorying native syntax uses of the dot under 2).
– smciJan 8 at 5:22

Re: "What would be improved by having some definition of a concept that Python itself doesn't define?", getting Python to work recursively the esp. when using JS/JSON(/HTML/XML/YAML) has long been a coding practice in Python (many of the examples I cited are that one same thing). And that meaning is well-defined on the JS/XML/HTML side. Also "enforce" is not necessary (once we merge questions with the first meaning), it really just boils down to the binary "Did you mean hierarchical JS-style? or native builtin Python syntax?"
– smciJan 8 at 5:27

Functional. Using getattr, setattr, etc to access and set attributes functionally via strings.

Enumerating attributes. Getting a list of all attributes relating to an object.

Using dot instead of getitem / [] notation. Improving access "for ease of use", often associated with a desire to create a variable number of variables.

The list goes on and on. I can only deduce there is no way to usefully aggregate all these uses of a specific notation. I'd also suggest "by notation" isn't the best way to learn a language. So if someone is actively seeking all uses of a particular notation, they are barking up the wrong tree.

The clear main use is "automatic getting/setting of nested chains of object attributes/dict keys". I didn't suggest making a laundry list of every possible case where Python uses a dot to access things, which is what you compiled here. I meant decoding when people explicitly talk about implementing "dot-notation" in Python. That would mean the use case where it is not part of the language syntax. Let me edit the original question to "main meanings" from "all the meanings", which was too expansive.
– smciJan 8 at 4:57

1

Based on what you said I revised the question to scope down to "separating meaning 2) (various use-cases in builtin syntax) as a group from meaning 1) (implementing JS-style)" and remove "all [the meanings]" from the title. I mean someday someone might say "What is the dot notation in f =1.35?", and yes we don't need to treat that sort of mention as a legit case either.
– smciJan 8 at 5:19

@smci, I know you are well-intentioned, but the problem remains that SO doesn't aim or have tools for aggregating answers at this granularity. The kind of things you can try: hard-linking via Related: xyz comments, making an index like this Q&A which may not go down well with community, or aggressively closing as dups for related but not identical duplicates (also won't go down well). It's tough for diligent organizers like yourself, but SO isn't set up for this.
– jppJan 8 at 9:46

With regard to the first meaning, the solution seems a mixture of 'Related:' links and some closing as warranted, similar to what you advise. I care less about the second meaning, it's a pile of years of broken cruft, much of which is invalidated by 3.x, but it seems impossible to reach a community consensus on doing anything to reduce the mess and confusion, so I'm not going to bother. The CW Q&A seems a good way to go, but that one was locked back in 2014 (why? can it be reopened? did people dislike that?)
– smciJan 8 at 10:00

1

@smci, With regards to that locked Q&A, the consensus (usually) is the material lies between the tag wiki and Q&A formats. Expanded, indexable tag-wikis with examples of how to ask good questions would be ideal. Sadly, there's no real investment (that I know of) in this area. What you can do is put this information on non-affiliated sopython.com (with the necessary approvals) and link to it from the tag wiki. This may be your best bet, and is better than just writing and sharing a blog as there is some community oversight.
– jppJan 8 at 11:24

thanks for the suggestions, but sopython.com/canon is not suitable either, it's only for canonical questions, not for a wiki of duplicate, near-duplicates and bad askings, such as I list here. That's the whole reason I came here to ask. A CW Q&A would have been ideal IMO (excluding plain bad askings), but that doesn't seem to be popular. So that just reduces us to "pick canonicals, close duplicates, add 'Related' link comments on near-duplicates and bad askings, and downvote bad askings. And absolutely not tag-wiki. You might like to edit that into your answer.
– smciJan 8 at 12:09

Not suitable for tag-wiki either, even neglecting that a hopelessly undefined language-agnostic dot-notation got burninated previously. I'm only talking about Python uses here, and ee do not need or want a tag for that.
– smciJan 8 at 12:11

@JonClements: but are you actually recommending I move this discussion there? It seems a much worse target: no comments or voting, a tiny audience, just community editing and presumably some inevitable revert-warring. It really looks like a terrible target for hosting discussions where people will inevitably have widely differing views. Even here on Meta is better. Better to set out all the different viewpoints to gather some sort of consensus.
– smciJan 8 at 12:47

1

@smci no - I'm not suggesting moving this discussion anywhere else... I'm just pointing that out as a potential option to write what is effectively a blog/how-to post for what you're trying to address here... it wouldn't fit well on the SO platform in sense.
– Jon Clements♦Jan 8 at 12:57

@JonClements: if you're concluding what I'm suggesting won't IYO fit anywhere on SO, isn't that per se a big problem? and in need of an SO solution? I still don't see why CW Q&A's are bad, the regex one looks great. Meanwhile what should I do with this, here on SO/Meta? It feels awfully broken that FGITW duplicate answers are more welcome here than community-minded attempts to clean up the crud and actually make the site welcoming for users with questions like the ones that motivated my post here. I see 7 downvotes here but zero proposed solutions.
– smciJan 8 at 14:51

@smci, I'm a big believer in self-answered Q&A. If you believe there is an on-topic Q&A on this matter, e.g. along the lines of "why does dot notation do this here, and this something else in this other situation?", then you seem perfectly placed to write such a self-answered Q&A. As such, I can't see a clear on-topic SO question anywhere within your Meta question. Which is likely why few people are interested.
– jppJan 13 at 18:45

@jpp: the clear on-topic SO question for the first meaning is "How to implement JS-style automatic getting/setting of nested chains of object attributes/dict keys (without breaking inheritance or other builtin behavior, and without impacting performance)". In all sincerity, how was that not clear? As to the lack of clarity of questions on the second meaning, that's less important than disambiguating and separating them from the first meaning.
– smciJan 13 at 18:50

@smci, One sentence itself doesn't make a question. But if you think that there's room to aggregate lots of information from various posts, it's possible to construct a canonical self-answered Q&A. Here's a recent example which was well received by the community. Such a broad Q&A rehashes stuff from lots of posts, sure, but it also coherently brings it altogether. You can hard link all the other posts to the canonical via "Related: How to implement JS-style getting/setting" since dupe-hammering old posts won't go down well.
– jppJan 13 at 18:55

@jpp ok but before any of us attempts to write a canonical Q&A, it seemed necessary to first confirm our collective understanding of the main Python senses in which 'dot-notation' is used by Python programmers. Which I believe we did. Next step is to research the "without breaking inheritance or other builtin behavior, and without impacting performance" aspect. (For example, is Box library generally agreed to be a good implementation? what are criticisms of it?)
– smciJan 13 at 19:06