Can you reference a class internally in Python?

If I have classes A and B, I basically want to do something like this:

  class A:
     myDict = {A: 3, B: 2}

Since my link is not in a function, the class is not fully loaded by the time I try to use it. How can I get around this?

+4
source share
1 answer

The correct solution is to move the dict outside the class

class A: pass A.mydict = {A: 3, B: 2} 

which will lead to exactly the values ​​you get if you can do what you ask.

+5
source

All Articles