Python name of class in class body

Viewed 2373

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

5 Answers
Related