[HN Gopher] Box - Python dictionary with dot notation
       ___________________________________________________________________
        
       Box - Python dictionary with dot notation
        
       Author : nothrowaways
       Score  : 11 points
       Date   : 2021-12-17 19:14 UTC (3 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | UncleEntity wrote:
       | Not sure I like how it converts spaces and drops non-text
       | characters, could possibly result in all sorts of hard to track
       | down problems methinks.
       | 
       | When I wrapped boost::property_tree using the C-API I did the
       | whole dot notation thing but it doesn't do any sort of conversion
       | -- key names with spaces or whatever have to be looked up with
       | prop["name"] or the getter function(s).
        
       | greenie_beans wrote:
       | this is neat. my first thought was, "why not just use a
       | dataclass?" but i guess this would do some different things than
       | a dataclass? and be easier to create than a dataclass?
        
       | wodenokoto wrote:
       | Huh, I've always seen those attribute dict, and seen a few
       | implementation in different projects over the years. They are
       | quite fun to build yourself, if you are a novice in Python
       | classes and inheritance.
        
       | rak1507 wrote:
       | Not to be harsh but why would anyone ever use this? It's just
       | some syntax sugar? (and over 3K loc... yikes)
        
         | jackbrookes wrote:
         | It's useful for APIs that return dictionaries that have a
         | reliable structure
        
           | rak1507 wrote:
           | But.. why not use foo['bar'] vs foo.bar? Are the extra 3
           | characters so annoying you have to rely on a new library?
        
             | aqeelat wrote:
             | It might be useful for auto completion when you're using
             | versions older than 3.8 and can't use TypedDict.
        
       | eulenteufel wrote:
       | I thought I wanted dictionaries with dot notation for a while.
       | After some time I realized I didn't care about dictionary
       | features like iterating over keys at all, I just needed a
       | namespace.
       | 
       | `from types import SimpleNamespace` works for me.
       | 
       | Of course I don't want to say that there's no need for box, just
       | that it's good to consider if you're actually looking for a
       | dictionary.
        
       ___________________________________________________________________
       (page generated 2021-12-17 23:02 UTC)