Timeline for How do I avoid the "self.x = x; self.y = y; self.z = z" pattern in __init__?
Current License: CC BY-SA 4.0
13 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 7, 2021 at 1:53 | history | edited | SuperStormer | CC BY-SA 4.0 |
edited body
|
S Feb 29, 2016 at 11:36 | history | suggested | Ɖiamond ǤeezeƦ | CC BY-SA 3.0 |
Corrected spelling mistake
|
Feb 29, 2016 at 11:17 | review | Suggested edits | |||
S Feb 29, 2016 at 11:36 | |||||
Feb 29, 2016 at 11:03 | audit | First posts | |||
Feb 29, 2016 at 11:14 | |||||
Feb 24, 2016 at 5:10 | audit | First posts | |||
Feb 24, 2016 at 5:11 | |||||
Feb 17, 2016 at 15:52 | audit | First posts | |||
Feb 17, 2016 at 16:19 | |||||
Feb 17, 2016 at 15:45 | comment | added | Lii |
That could be made into a function which takes the return value of locals : set_fields_from_locals(locals()) . Then it's no longer than the more magical decorator based solutions.
|
|
Feb 5, 2016 at 5:05 | audit | First posts | |||
Feb 5, 2016 at 5:05 | |||||
Feb 4, 2016 at 3:32 | comment | added | ShadowRanger |
For slightly more efficient tests, if k != "self": could be changed to if v is not self: , cheap identity test, rather than string comparison. I suppose technically __init__ could be called a second time after construction and passed self as a subsequent argument, but I really don't want to think what sort of monster would do that. :-)
|
|
Feb 4, 2016 at 2:25 | comment | added | cat | @bernie (or is it bemie?), sometimes ke r ning is hard | |
Feb 4, 2016 at 1:32 | history | edited | Joran Beasley | CC BY-SA 3.0 |
added 37 characters in body
|
Feb 4, 2016 at 1:30 | comment | added | John La Rooy | Then the object will need cyclic garbage collection since it has itself as an attribute | |
Feb 4, 2016 at 1:27 | history | answered | Joran Beasley | CC BY-SA 3.0 |