Hacker News new | ask | show | jobs
by mixmastamyk 3224 days ago
The problem with python class definition is the need to write instance vars 3x:

    def __init__(self, foo)
        self.foo = foo
There is an attrs package and new proposal (https://github.com/ericvsmith/dataclasses/blob/master/pep-xx...) to remedy that.
1 comments

Yeah, I guess I normally don't deal with enough properties like that for it to be a big deal in my workflow. When it's come up I've generally done something like:

    class Foo:
        bar = 42

        def __init__(self, **kwargs):
            self.__dict__.update(**kwargs)
But I agree that's not a super robust solution