Using an attribute of the current class instance as a default value for method’s parameter [duplicate]

It’s written as:

def my_function(self, param_one=None): # Or custom sentinel if None is vaild
    if param_one is None:
        param_one = self.one_of_the_vars

And I think it’s safe to say that will never happen in Python due to the nature that self doesn’t really exist until the function starts… (you can’t reference it, in its own definition – like everything else)

For example: you can’t do d = {'x': 3, 'y': d['x'] * 5}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)