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

  1. Python conditional derivation
  2. Python list derivation
  3. Python dictionary derivation
  4. Python variable length arguments *argc/**kargcs
  5. The Python anonymous function lambda
  6. Python Return logical judgment expressions
  7. Python is and == are different
  8. Python is mutable and immutable
  9. Shallow and deep Python copies
  10. Python Exception handling
  11. The Python thread creates and passes parameters
  12. Python thread mutex Lock
  13. Python thread time Event
  14. The Python thread Condition variable Condition
  15. Python thread Timer Timer
  16. Python thread Semaphore
  17. The Python thread Barrier object
  18. Python Thread Queue – FIFO
  19. Python thread queue LifoQueue – LIFO
  20. Python 线程优先队列 PriorityQueue
  21. ThreadPoolExecutor(1)
  22. ThreadPoolExecutor(2)
  23. The Python Process module
  24. The Python Process is different from the threading Process
  25. Queue/Pipe for communication between Python processes
  26. Python process Pool multiprocessing.pool
  27. Python GIL lock

The Python reload function is to be reloaded

This article is posted by the blog – Ape says Programming Ape says Programming!