Python3-无法在__import__对象上调用reload()? [英] Python3 - reload() can not be called on __import__ object?
问题描述
好吧,出于多种原因,我在Python2中使用时间最长的时间是s = __import__('parse')
,现在我需要将某些项目转换为Python3(主要是由于SSL).
Ok so for a number of reasons, I've been using s = __import__('parse')
for the longest time in Python2, now I sorta need to being my transitions to Python3 for certain projects (mainly due to SSL).
但是据我发现,Python3中没有reload()
等价物.
只有一种选择:
But there's no reload()
equivilant in Python3 as far as i've spotted.
There's only one option:
import parse
parse.reload() #works
但是我真的非常需要它来工作:
But I really, really need this to work:
parse = __import__('parse')
parse.reload()
或
reload(parse)
关于如何使其在Python3中工作的任何想法?
Any ideas on how to get it working in Python3?
推荐答案
reload
内置函数已移至Python 3.4中的importlib
模块:
The reload
built-in function has been moved to importlib
module in Python 3.4:
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
移至 Python 3.4 + 中的模块.来自 Python 3.4中的新功能:
As pointed out by @JPaget in comments reload()
function has been moved from imp
to importlib
module in Python 3.4+. From what's new in Python 3.4:
reload()
功能已从imp
移至importlib
,作为imp
模块弃用
The
reload()
function has been moved fromimp
toimportlib
as part of theimp
module deprecation
这篇关于Python3-无法在__import__对象上调用reload()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!