Python Module sys: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 15: Line 15:
====<tt>sys.modules</tt>====
====<tt>sys.modules</tt>====
A dictionary that maps module names to modules instances, for modules have already been loaded. It can be manipulated to force reloading of modules. 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 <code>sys.modules.copy()</code> or <code>tuple(sys.modules)</code> to avoid exceptions as its size may change during iteration as a side effect of code or activity in other threads.
A dictionary that maps module names to modules instances, for modules have already been loaded. It can be manipulated to force reloading of modules. 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 <code>sys.modules.copy()</code> or <code>tuple(sys.modules)</code> to avoid exceptions as its size may change during iteration as a side effect of code or activity in other threads.
====<tt>sys.version_info</tt>====

Revision as of 19:21, 6 September 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

Command Line Argument Processing

sys.modules

A dictionary that maps module names to modules instances, for modules have already been loaded. It can be manipulated to force reloading of modules. 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.

sys.version_info