开发者

How do I replicate "from module import class" with __import__() or django.utils.importlib?

开发者 https://www.devze.com 2023-02-28 04:32 出处:网络
I want to import a class from python module.The module contains multiple classes and which one I need is dete开发者_如何学Pythonrmined by a string at runtime.

I want to import a class from python module. The module contains multiple classes and which one I need is dete开发者_如何学Pythonrmined by a string at runtime.

Edit: I'm using python 2.6.5, django 1.3.


With judicious use of getattr().


MyClass = getattr(mymodule, myclass_name)


Or import(module,globals(),locals(),['classname',],-1)

0

精彩评论

暂无评论...
验证码 换一张
取 消