如何将类定义中的默认值设置为类'实例变量?
之一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
答案 0 :(得分:1)
使用其他值,并检查它:
def do_something(self, data_file=None):
if data_file is None:
data_file = self.data
...etc...