Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

python - Python3 - reload() can not be called on __import__ object?

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?

question from:https://stackoverflow.com/questions/18249459/python3-reload-can-not-be-called-on-import-object

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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:

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...