Can I use self parameters in my method definition in python?
class Test:
def __init__(self, path):
self.path = pathlib.Path(path)
def lol(self, destination=self.path):
x = do_stuff(destination)
return x
I can make def lol(self, destination) and use it this way test_obj.lol(test_obj.path). But is there a way to set default destination arg to self.path? The other way posted below(based on this answers), but can I refactor it somehow and make it more elegant? Maybe there is new solution in python3.+ versions.
def lol(self, destination=None):
if destination in None:
destination = self.path
x = do_stuff(destination)
return x
__init__. There you have access to the instance variables.__init__from outside?def lol(self, destination=self.path):this declaration already has the default you are looking for. Just pass whatever you want to, to destination if you want it to take any other value.self.lol = lol. Then you can access it normally. I'll post an example later.pathproperty.