Home >Backend Development >Python Tutorial >Python reload module method

Python reload module method

大家讲道理
大家讲道理Original
2016-11-07 16:24:451356browse

To prevent the problem of two modules importing each other, Python only imports all modules once by default. If you need to re-import the module,

Python2.7 can use reload() directly, and Python3 can use the following methods:

method One: Basic method

from imp import reload
reload(module)

Method two: According to the routine, it can be like this

import imp
imp.reload(module)

Method three: Look at imp.py, and there is a discovery, so it can still be like this

import importlib
importlib.reload(module)

Method four: According to the laws of nature, of course it can also be like this

from importlib import reload
reload(module)


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn