gpt4 book ai didi

python : How to import a module if I have its path as a string?

转载 作者:行者123 更新时间:2023-11-28 20:11:32 28 4
gpt4 key购买 nike

假设我在字符串中有一个模块的路径 module_to_be_imported = 'a.b.module'
如何导入它?

最佳答案

>>> m = __import__('xml.sax')
>>> m.__name__
'xml'
>>> m = __import__('xml.sax', fromlist=[''])
>>> m.__name__
'xml.sax'

关于 python : How to import a module if I have its path as a string?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3102252/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com