You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python 3.6中如何使用Importlib从字符串创建类对象

我知道这类问题已经被问过好多次啦,但还是麻烦你看看我的情况~我正试着参照《将字符串转换为Python类对象》里的方法,在Python 3.6环境下通过字符串来创建类。我的utils.py代码是这样的:

class Foo(object):
    def __init__(self):
        print("In the constructor of Foo")
    def What(self):
        print("so what ... ")

class FooParam(object):
    def __init__(self, v):
        self.value = v
        print("In the constructor of FooParam")
    def What(self):
        print("Value=" % self.value)
        print("So what now ...")

内容的提问来源于stack exchange,提问作者lightsunray

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:21:17