1 year ago

#75559

test-img

mm rnm

Is there a PEP styleguide for class member initialization?

Assuming I want to initialize every member variable in __init__, is there a recommended approach or style according to PEP? Especially for classes where the constructor also calls methods and has a bunch of member variables, I currently use the first style (A):

    class A(object):
        def __init__(self):
            self.a, self.b, self.c = [None] * 3
     
            self._populate_members()


    class B(object):
        def __init__(self):
            self.a = None
            self.b = None
            self.c = None

            self._populate_members()

Is there a PEP rule/recommendation about this?

python

class

initialization

readability

pep

0 Answers

Your Answer

Accepted video resources