Is it possible to get the class name within the body of a class definition?
For example,
class Foo():
x = magic() # x should now be 'Foo'
I know that I can do this statically outside of the class body using a class method:
class Bar():
@classmethod
def magic(cls):
print cls.__name__
Bar.magic()
However this isn't what I want, I want the class name in the class body
__prepare__
method of metaclasses in Python 3 allows you to add the name to the class dictionary before the body of the class starts executing (from where you can then use it) – Abacist