-1

My question is largely one of style or convention; however, it could have consequences which are not obvious to me that would effect which style is used.

If I have a class where instance attributes are defined by parameters to __init__, is it acceptable to access these parameters directly, rather than by the instance attribute? An example is given below:

from some_module import MyOtherClass

class MyClass(object)
    def __init__(self, uno, dos):
        self.uno = uno
        self.dos = dos

        """ This? """
        MyOtherClass(uno)
        MyOtherClass(dos)

        """ Or this? """
        MyOtherClass(self.uno)
        MyOtherClass(self.dos)
Johndt
  • 4,187
  • 1
  • 23
  • 29
  • You have a callable module? (`MyOtherObject`) Or it should be something like `from other_module import MyOtherClass`. – wim Jan 13 '17 at 20:09
  • @wim The latter is correct; fixed. – Johndt Jan 13 '17 at 20:16
  • To the duplicate: Thanks! I searched around a bit and couldn't find a similar question- I guess I couldn't find it because the title of that one is kind of incorrect. – Johndt Jan 13 '17 at 20:18

1 Answers1

1

Sometimes there is extra logic in each initialization:

def __init__(self, uno, dos=None):
    self.uno = list(uno)
    self.dos = dos or default_dos()

In that case, reusing the argument would result in an error.

Josh Lee
  • 171,072
  • 38
  • 269
  • 275