2018-03-24 17:18 GMT+03:00 Tin Tvrtković <[email protected]>:
>
> I've found that, if a class has more than one attribute, instead of
> creating an init like this:
>
> self.a = a
> self.b = b
> self.c = c
>
> it's faster to do this:
>
> self.__dict__ = {'a': a, 'b': b, 'c': c}
>
> i.e. to replace the instance dictionary altogether. On PyPy, their core
> devs inform me this is a bad idea because the instance dictionary is
> special there, so we won't be doing this on PyPy.
>
But why you need to replace it? When you can just update it:
class C:
def __init__(self, a, b, c):
self.__dict__.update({'a': a, 'b': b, 'c': c})
I'm certainly not a developer. Just out of curiosity.
With kind regards,
-gdg
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com