Python grab class in class definition.
Posted
by epochwolf
on Stack Overflow
See other posts from Stack Overflow
or by epochwolf
Published on 2010-05-02T01:42:47Z
Indexed on
2010/05/02
1:47 UTC
Read the original article
Hit count: 242
python
|reflection
I don't even know how to explain this, so here is the code I'm trying.
class Test:
type = self.__name__ #self doesn't work, how do I get a reference to Test?
class Test2(Test):
pass
#Test2.type should return "Test2"
The reason I'm even trying this is I'm working on creating a base class for an orm I'm using. I want to avoid defining the table name for every model I have. Also knowing what the limits of python is will help me avoid wasting time trying impossible things.
© Stack Overflow or respective owner