39

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).

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()

or

reload(parse)

Any ideas on how to get it working in Python3?

4

1 回答 1

76

Python 3.4中的reload内置函数已移至模块: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 在注释功能中指出的那样,在Python 3.4+reload()中已从模块imp移至importlib模块。从Python 3.4 的新特性

作为模块弃用的一部分,该reload()功能已从imp移至importlibimp

于 2013-08-15T09:06:27.537 回答