0

How can I set the default value in the class definition to one of the class' instance variable?

class SomeClass:
    def __init__(self, data):
        self.data = data

    def do_something(self, data_file=self.data):  # Here

        # modify the data and return to itself using recursion.
        if something:
            return self.do_something(data_file)
        else:
            return data_file
tommyip
  • 430
  • 7
  • 16

1 Answers1

1

Use another value, and check for it:

def do_something(self, data_file=None):
    if data_file is None:
        data_file = self.data

    ...etc...
RemcoGerlich
  • 30,470
  • 6
  • 61
  • 79