addict
addict copied to clipboard
Dict Attributes not available to Autocomplete and not present in __dict__
Hi, When I convert a normal dictionary like
some_dict = {'a': 1, 'b': 2, 'c': 3}
to an attribute dictionary via
from addict import Dict
attribute_dict = Dict(some_dict)
I would expect being able to hit tab in order to access an attribute via autocomplete (as usual with classes). However, all the keys from some_dict
are not present. Also attribute_dict.__dict__
only returns the following:
{'__parent': None, '__key': None, '__frozen': False}
.
Is that intended, or am I missing something on my side?
As a side note, I installed addict
version 2.4.0 via pip.
Same here: it would be great and convenient if addict
can support autocompletion in common IDEs.
@zyLiu6707 In the meantime I developed my own solution since I was not sattisfied with addict and other comparable projects.
It's called MetaDict and behaves exactly like a dict
with the addition of enabling (nested) attribute-style key access/assignment and IDE autocompletion.
It might suit your usecase :)
Thank you Lars, I'll check it out :)
I modified by adding this to the addict.py and autocomplete start working . Thanks to https://stackoverflow.com/questions/51917470/what-does-tab-completion-in-ipython-or-jupyter-seek-in-order-to-suggest-alternat can you make this change? not versed enough in github pull requests etc else I would have done it def dir(self): super_dir = super().dir() string_keys = [key for key in self if type(key) is str] return super_dir + [key for key in string_keys if key not in super_dir]