6 ms·
I prefer the simpler: class A(object): def __init__(self, x, y): self.__dict__.update((k,v) for k,v in locals().items() if k != 'self')
by jwegan 13y ago
I prefer the simpler:
class A(object):
def __init__(self, x, y):
self.__dict__.update((k,v) for k,v in locals().items() if k != 'self')
- krupan 13y agoSeriously, I couldn't finish the article once I saw he wasn't using locals. Is there some hidden gotcha that we are missing here that he's taking care of with his more complicated approach?
- nollidge 13y agoBecause that would include non-argument locals, if you have any.
- oinksoft 13y agoI don't like code to casually access the inner dict. Now you have to maintain your `k != 'self'` (ugly in its own right) for each argument you want to exclude from this rule. The explicit version is superior, this is needlessly slow and complicated.