Reputation: 185
If I have classes A and B, I basically want to do something like this:
class A: myDict = {A: 3, B: 2}
Since my reference isn't in a function, the class hasn't fully loaded by the time I try to use it. How can I get around this?
Upvotes: 4
Views: 1076
Reputation: 156158
The proper solution is to move the dict outside the class
class A:
pass
A.mydict = {A: 3, B: 2}
which will result in exactly the values you would get if you could do what you ask for.
Upvotes: 5