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.

9
  • 31
    Not all receptiveness is bad. Keep in mind that Python's class model doesn't include explicit definition of instance attributes, so these assignments are the self-documenting equivalents.
    – chepner
    Commented Feb 4, 2016 at 1:33
  • 4
    @chepner: Well, doesn't require explicit definition. You can use __slots__ for the purpose though; it's mildly unpythonic (more verbose to get memory savings), but I like it largely to avoid the risk of auto-vivifying a whole new attribute if I typo the name. Commented Feb 4, 2016 at 3:30
  • 2
    Any good editor will have templates. You type ini <shortcut> x, y, z): <shortcut> and you are done.
    – Gere
    Commented Feb 4, 2016 at 5:52
  • 3
    Namedtuples are awesome, if you want an immutable value object. If you want a regular, mutable class, you can't use them. Commented Feb 4, 2016 at 15:16
  • 4
    "Don't" is a good option, any option available will kill the method signature (and thus potentially the whole interface). Besides, if your classes have a unbearable amount of fields to initialize, you might want to consider splitting them.
    – Kroltan
    Commented Feb 5, 2016 at 0:13