Chris Angelico <[email protected]>: > On Fri, Sep 22, 2017 at 10:26 PM, Marko Rauhamaa <[email protected]> wrote: >> Chris Angelico <[email protected]>: >>> (Side point: Your slot_ref function is rather bizarre. It's a closure >>> AND a class, just in case one of them isn't sufficient. >> >> I don't see anything bizarre in it at all.
> Sure you *can* do it. It's perfectly legal Python syntax. But what's > the point? The class alone will do it. > > class slot_ref: > def __init__(self, ns, key): > self.ns = ns; self.key = key > def get(self): return self.ns[self.key] > def set(self, value): self.ns[self.key] = value > > That should be drop-in compatible with your original function/class > hybrid, complete with following the naming convention for functions > rather than classes. You are right. That one would be the way to go here. Marko -- https://mail.python.org/mailman/listinfo/python-list
