Upload files to "/"
This commit is contained in:
commit
d23f719359
2 changed files with 27 additions and 0 deletions
24
Self_alter.py
Normal file
24
Self_alter.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import lib_module
|
||||||
|
|
||||||
|
def update():
|
||||||
|
import importlib
|
||||||
|
importlib.reload(lib_module)
|
||||||
|
del importlib
|
||||||
|
def change_my_lib():
|
||||||
|
with open("lib_module.py", "w") as libby:
|
||||||
|
libby.write("def func_in_lib():\n\tprint('new logic!')\n")
|
||||||
|
|
||||||
|
def reset_project_demo():
|
||||||
|
with open("lib_module.py", "w") as libby:
|
||||||
|
libby.write("def func_in_lib():\n\tprint('Old logic :(')\n")
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
lib_module.func_in_lib()
|
||||||
|
change_my_lib()
|
||||||
|
lib_module.func_in_lib()
|
||||||
|
# Notice the logic doesn't change till we update it. '
|
||||||
|
update()
|
||||||
|
lib_module.func_in_lib()
|
||||||
|
# Look, now we performed a hot reload of a library without turning off the program
|
||||||
|
# It should be obvious where this can be useful.
|
||||||
|
reset_project_demo()
|
||||||
3
lib_module.py
Normal file
3
lib_module.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
def func_in_lib():
|
||||||
|
print("Old logic :( ")
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue