commit d23f7193591ebbbdd0f0cf817d242047e4d293c3 Author: Gwyn Date: Fri Feb 6 14:19:32 2026 -0500 Upload files to "/" diff --git a/Self_alter.py b/Self_alter.py new file mode 100644 index 0000000..26d729b --- /dev/null +++ b/Self_alter.py @@ -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() \ No newline at end of file diff --git a/lib_module.py b/lib_module.py new file mode 100644 index 0000000..1ff09af --- /dev/null +++ b/lib_module.py @@ -0,0 +1,3 @@ +def func_in_lib(): + print("Old logic :( ") + \ No newline at end of file