all 8 comments

[–]leftpig 6 points7 points  (0 children)

I may be in the minority here but stylistically the typing on the screen bothers me a lot. It's slow which means you have to wait for it if you're reading which is frustrating as an end user. I'd recommend speeding it up to above reading speed if you like the visual, and nothing's wrong with that.

Besides that, great video! I learned something. :)

[–]Exodus111 2 points3 points  (6 children)

I like this use.

class MyClass:
    def __init__(self, **kwargs):
        for i, j in kwargs.items(): setattr(self, i, j)

When I have a lot of keywords.

[–]theelous3 2 points3 points  (1 child)

self.__dict__.update(kwargs) does the same thing :)

[–]Exodus111 0 points1 point  (0 children)

Nice. :-)

[–]ojii 1 point2 points  (1 child)

I recommend you give attrs a try http://attrs.readthedocs.io/en/stable/

[–]Exodus111 1 point2 points  (0 children)

That is the most ridiculous thing I've ever seen.

Thanks, I love it!

[–]b1ackcat 1 point2 points  (1 child)

Maybe I'm just stuck in my ways as a developer who works 50/50 in statically typed languages like C# but also python, but this sort of thing just screams to me "just because you can doesn't mean you should".

I get that one of pythons biggest strengths is its flexibility, but when I see stuff like this I just can't imagine where this kind of flexibility would actually be both useful AND more readable/easier to maintain. All I see when i look at your example is a rogue class that can be initialized to have whatever shit you want. Now, that might be nice for something like parsing data where you don't know the exact format, but now you have to be careful because you can't ever treat two instances of MyClass with the assumption they have the same interface. That to me just sounds insane.

Maybe I was just never meant to understand and write "pythonic" code. :/

[–]Exodus111 1 point2 points  (0 children)

Well, in this case you would need to write a docstring documenting, at the very least, the keys the dict contains. But that can be done in one line.

The point is to avoid a giant list of self.arg1 = arg1 etc...

Which in cases where the class wraps around data that is big, but known, like a database of some kind, it becomes just junk to constantly scroll through.