0
class Test:
  def __init__(self, value):
    self.some_attribute = value

  def hello(self):
    print(self.some_attribute)

Test.hello

Is it possible to get the type of the class when passing Test.hello as an argument in a function? At a later time I want to be able to use the constructor of class Test, and then invoke the method hello on the instance.

I know that what I want is possible like this:

Test.hello(Test("test"))

However I'm not sure how i can extract the from Test.hello when it is passed like an argument.

stef
  • 21
  • 2
  • There is no good way to do this, but there might be various hacks (in the simplest case of a class defined at the module level, you can do something like `Test.hello.__globals__[Test.hello.__qualname__.split('.')[0]]`) – juanpa.arrivillaga Apr 06 '22 at 18:08

0 Answers0