directory
- Python Reload function
- 2.Python reload function is used
- Three. Guess you like it
Python Basics: Python Basics
Python Reload function
- In python2. x ** Reload function ** is a built-in Python function;
- In python3. x, the reload function can be used only after importing imp third-party libraries.
#! Usr /bin/env python # -\_- coding:utf-8 \_\_- """ @author: www.codersrc.com @file :Python reload function. Py @time :2021/05/09 08:00 @Motto: no short step no thousand miles, no small flow into a river sea, program life needs to keep on the accumulation of wonderful! # python3 from IMP import reload(module) # python3 from IMP import reload(module)Copy the code
Description:
1. The reload function must be a successfully imported module. If the reload function is used, the module has already been imported successfully using import or from.
2. The import statement in Python can import module files, but the import statement only executes the code in the module file the first time it is imported, and then saves the imported module file into memory. When it is imported again, Python retrieves the module file from memory without executing its contents, and the Reload function forces Python to reimport and execute the module file.
2.Python reload function is used
Suppose there is a module file a.py:
#! Usr /bin/env python # -* -coding :utf-8 _*- """ @author: www.codersrc.com @file :Python reload function. Py @time :2021/05/09 08:00 @Motto: no short step no thousand miles, no small flow into a river sea, program life needs to keep on the accumulation of wonderful! """ def fun(): print(" Python tutorial www.codersrc.com")Copy the code
Then execute the following code on the interactive console:
#! Usr /bin/env python # -* -coding :utf-8 _*- """ @author: www.codersrc.com @file :Python reload function. Py @time :2021/05/09 08:00 @Motto: no short step no thousand miles, no small flow into a river sea, program life needs to keep on the accumulation of wonderful! """ >>>import a >>> a.run () "Python tutorial www.codersrc.com"Copy the code
Then we do not exit the interactive console, and modify a.py:
#! Usr /bin/env python # -* -coding :utf-8 _*- """ @author: www.codersrc.com @file :Python reload function. Py @time :2021/05/09 08:00 @Motto: no short step no thousand miles, no small flow into a river sea, program life needs to keep on the accumulation of wonderful! """ def fun(): pirnt(" the ape says Python www.codersrc.com")Copy the code
Then on the interactive console, execute the following code:
#! Usr /bin/env python # -* -coding :utf-8 _*- """ @author: www.codersrc.com @file :Python reload function. Py @time :2021/05/09 08:00 @Motto: no short step no thousand miles, no small flow into a river sea, program life needs to keep on the accumulation of wonderful! """ >>>import a >>>a. run () >>>from imp import reload But the imp a function of the module > > > reload (a) < module 'a' form '/ home/chaochao/python/Amy polumbo y' > > > > a.f UN # () for the module file Amy polumbo y reflect changes "The ape said Python www.codersrc.com"Copy the code
Three. Guess you like it
- Python conditional derivation
- Python list derivation
- Python dictionary derivation
- Python variable length arguments *argc/**kargcs
- The Python anonymous function lambda
- Python Return logical judgment expressions
- Python is and == are different
- Python is mutable and immutable
- Shallow and deep Python copies
- Python Exception handling
- The Python thread creates and passes parameters
- Python thread mutex Lock
- Python thread time Event
- The Python thread Condition variable Condition
- Python thread Timer Timer
- Python thread Semaphore
- The Python thread Barrier object
- Python Thread Queue – FIFO
- Python thread queue LifoQueue – LIFO
- Python 线程优先队列 PriorityQueue
- ThreadPoolExecutor(1)
- ThreadPoolExecutor(2)
- The Python Process module
- The Python Process is different from the threading Process
- Queue/Pipe for communication between Python processes
- Python process Pool multiprocessing.pool
- Python GIL lock
The Python reload function is to be reloaded
This article is posted by the blog – Ape says Programming Ape says Programming!