Python reload module method

高洛峰
Release: 2016-11-23 13:30:21
Original
1114 people have browsed it

In order 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 1: Basic method

from imp import reload

reload(module)

Method 2: Follow the routine, you can do this

import imp

imp.reload(module)

Method 3: Look Looking at imp.py, I found something, so it can also be like this

import importlib

importlib.reload(module)

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

from importlib import reload

reload(module)


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!