Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • Then the object will need cyclic garbage collection since it has itself as an attribute Commented Feb 4, 2016 at 1:30
  • 3
    @bernie (or is it bemie?), sometimes ke r ning is hard
    – cat
    Commented Feb 4, 2016 at 2:25
  • 4
    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. :-) Commented Feb 4, 2016 at 3:32
  • 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.
    – Lii
    Commented Feb 17, 2016 at 15:45