Python Module sys: Difference between revisions
Jump to navigation
Jump to search
Line 11: | Line 11: | ||
====<tt>sys.argv</tt>==== | ====<tt>sys.argv</tt>==== | ||
{{Internal|Shell_Interaction_in_Python#Command_Line_Argument_Processing|Command Line Argument Processing}} | |||
====<tt>sys.modules</tt>==== | ====<tt>sys.modules</tt>==== | ||
This is a dictionary that maps module names to modules which have already been loaded. This can be manipulated to force reloading of modules and other tricks. However, replacing the dictionary will not necessarily work as expected and deleting essential items from the dictionary may cause Python to fail. If you want to iterate over this global dictionary always use sys.modules.copy() or tuple(sys.modules) to avoid exceptions as its size may change during iteration as a side effect of code or activity in other threads. | This is a dictionary that maps module names to modules which have already been loaded. This can be manipulated to force reloading of modules and other tricks. However, replacing the dictionary will not necessarily work as expected and deleting essential items from the dictionary may cause Python to fail. If you want to iterate over this global dictionary always use sys.modules.copy() or tuple(sys.modules) to avoid exceptions as its size may change during iteration as a side effect of code or activity in other threads. |
Revision as of 02:05, 8 July 2022
External
Internal
Overview
This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter.
Variables
sys.argv
sys.modules
This is a dictionary that maps module names to modules which have already been loaded. This can be manipulated to force reloading of modules and other tricks. However, replacing the dictionary will not necessarily work as expected and deleting essential items from the dictionary may cause Python to fail. If you want to iterate over this global dictionary always use sys.modules.copy() or tuple(sys.modules) to avoid exceptions as its size may change during iteration as a side effect of code or activity in other threads.