What does 'del self.self ' in an __init__ function mean?

The line: self.__dict__.update(locals()) results in three names being bound as attributes of self: self, attribute_1, attribute_2. The del self.self simply removes the unwanted self attribute on the object named by the name self.

This is lazy. It would be better to simply have the two lines:

self.attribute_1 = attribute_1
self.attribute_2 = attribute_2

self is a local variable, so it appears in locals().

self.__dict__.update(locals()) adds an attribute to the new object for every local variable, including self. Since that attribute is apparently not required, it gets deleted.

Tags:

Python