gpt4 book ai didi

Python3 - 不能在 __import__ 对象上调用 reload()?

转载 作者:IT老高 更新时间:2023-10-28 21:51:02 25 4
gpt4 key购买 nike

好吧,由于多种原因,我在 Python2 中使用 s = __import__('parse') 的时间最长,现在我肯定需要过渡到 Python3项目(主要是由于 SSL)。

但据我所知,Python3 中没有 reload() 等效项。只有一种选择:

import parse
parse.reload() #works

但我真的,真的需要这个来工作:

parse = __import__('parse')
parse.reload()

reload(parse)

关于如何让它在 Python3 中工作的任何想法?

最佳答案

reload 内置函数已移至 Python 3.4 中的 importlib 模块:

In [18]: from importlib import reload

In [19]: reload?
Reload the module and return it.

The module must have been successfully imported before.

正如@JPaget 在评论 reload() 中指出的那样函数已从 imp 移出至importlib Python 3.4+ 中的模块。来自 what's new in Python 3.4 :

The reload() function has been moved from imp to importlib as part of the imp module deprecation

关于Python3 - 不能在 __import__ 对象上调用 reload()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18249459/

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