python pass object as argument
70,590
So long as something
has a .do
method, that should work as given (once you fix your indentation and order of declaration). Have you tried running it?
This is (more or less) how a lot of standard functions work - for example, the built-in len
function is pretty much
def len(obj):
return obj.__len__()
Author by
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
How can I pass an object as an argument to a class method and call the method of the passed object when the class method is called?
Say I have:
class myclass: def __init__(self): pass def myfunc(self, something): something.do() anobject = blah.xyz() another_obj = myclass() another_obj.myfunc(anobject)