Get python class object from class name string in the same module

前端 未结 3 421
迷失自我
迷失自我 2020-12-01 03:43

I have a class

class Foo():
    def some_method():
        pass

And another class in the same module:

clas         


        
3条回答
  •  臣服心动
    2020-12-01 03:59

    globals()[class_name]
    

    Note that if this isn't strictly necessary, you may want to refactor your code to not use it.

提交回复
热议问题