Using self.* as default value for a method [duplicate]
Solution 1:
Use a default of None
and detect that.
def save_file(self, outputfilename=None):
if outputfilename is None:
outputfilename = self.image_filename
self.file.read(outputfilename)
....
Solution 2:
The documentation states:
Default parameter values are evaluated when the function definition is executed.
This explains why the instance cannot be referenced. As others have said, use None as your default and fix up the value at function execution time when the instance is available.