Python: Reference to a class from a string?

后端 未结 4 514
春和景丽
春和景丽 2020-12-11 10:51

How to use a string containing a class name to reference a class itself?
See this (not working) exemple...

class WrapperClass:
    def display_var(self):         


        
4条回答
  •  -上瘾入骨i
    2020-12-11 11:52

    Your example would work if you called print self.__class__.var. I don't think there's any need to use the name.

提交回复
热议问题