On 28Dec2019 19:19, Tim Chase <python.l...@tim.thechases.com> wrote:
Inside a class, I tend to roughly follow

 __new__ (if present)
 __init__
 other dunder methods
 subsequent methods alphabetically

I put the factory methods up near __init__, ahead of other methods. But after most dunders. Here I mean things like this:

 class Foo:

   def __init__(....):

   @classmethod
   def from_bytes(cls, bs, ...):
     ... parse out of `bs` and then finish with something like ...
     return cls(parsed-stuff)

which calls the "conventional" __init__ as normal.

And I often group methods of similar purpose together, rather than alphabetically. For example, if there's a few methods for transribing the object, they might land together.

Cheers,
Cameron Simpson <c...@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to