2 ms·
Seems like it may take a little more than one line, this errors for me: >>> a = tree() >>> a.__getattr__ = a.__getitem__
by afhof 14y ago
Seems like it may take a little more than one line, this errors for me:
>>> a = tree()
>>> a.__getattr__ = a.__getitem__
- albertzeyer 14y agoYea, sure it becomes more than one line (or at least I don't know a good one-line-way) but I wouldn't count that as an issue. It errors for you because it is a defaultdict instance and doesn't allow attribute overwrites. This should work: class tree(defaultdict): def __init__(self): defaultdict.__init__(self, tree) __getattr__ = defaultdict.__getitem__ __setattr__ = defaultdict.__setitem__ Edit: It doesn't work with the simple assignment because of the mentioned bug. Ofc the fix is trivial. See the code from beagle3.