Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would also agree that having too many attributes is probably a sign of insufficient abstraction, which is usually harder to develop &amp; debug, and so changing your design is probably a good idea.</p> <p>But, you do have a gold badge, so you've obviously been around and (probably) know what you are doing, and might have a reason to do this. In that case, I think it's a good idea to split up the initialization by category like you suggested. The only suggestion I would have is to use _ on the sub-init functions to signal to a user they aren't intended for normal use i.e.</p> <pre><code>class A: def __init__(self): self.member0 = "a" self.__init_other_stuff() def __init_other_stuff(self): self.member1 = "b" self.member2 = "c" </code></pre> <p>etc. This also hides them from tab-completion in most consoles &amp; editors. </p> <p>Your other choice is to make this class a subclass of multiple classes that implement part of the interface if you really need A to contain those items directly, i.e. do something like this:</p> <pre><code>class Logger(object): def __init__(self): self.logparam = 1 class NetworkSource(object): def __init__(self): self.netparam = 2 class A(Logger, NetworkSource): def __init__(self): Logger.__init__(self) NetworkSource.__init__(self) In [2]: a = A() In [3]: a.&lt;tab&gt; a.logparam a.netparam </code></pre> <p>Then it would get the functionality of both classes, while having a relatively short init. Multiple inheritance is conceptually a little more complicated though IMHO. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload