-2
class a:
    @staticmethod
    def aa():
    # find class b name
    pass
 
class b:
    object = a()
        
b.object.aa()

I want to get the name of the class b inside of the aa method of class a because the aa method is static method I cant pass arguments like self in here.

hamzeh_pm
  • 141
  • 7
  • hi, interesting, perhaps [getframeinfo](https://stackoverflow.com/questions/2654113/how-to-get-the-callers-method-name-in-the-called-method) might help – jspcal Jun 14 '21 at 19:26
  • 1
    I would avoid using `object`, as it is a reserved word. – Ben Y Jun 14 '21 at 19:26
  • What's the use case for this? Why doens't `aa()` take this as an explicit parameter? What if `aa` isn't called from a class? – Barmar Jun 14 '21 at 19:29
  • @gold_cy It's not being called from a method. – Barmar Jun 14 '21 at 19:30
  • @BenY it is just an example, i wont call my class a either :) – hamzeh_pm Jun 15 '21 at 03:11
  • i try to create DAL, and try to understand how Django do it, in Django if you want to query the database use yourmodelname.objects.all() -> list[yourmodel] for example – hamzeh_pm Jun 15 '21 at 03:13
  • it is not duplicate question and the answer wont provide me anything, how it come the question is closed, the caller frame is main frame of the program i want to find out the class name which i initiate this class from – hamzeh_pm Jun 15 '21 at 03:27

1 Answers1

0

If you're doing stuff with stack frames (as in who called the method), I would recommend reading the documentation on the stack() method provided in the inspect module.

Ben Y
  • 785
  • 3
  • 16