- Python Features
- Python Installation
- PyCharm Configuration
- Python Variables
- Python Data Types
- Python If Else
- Python Loops
- Python Strings
- Python Lists
- Python Tuples
- Python List Vs Tuple
- Python Sets
- Python Dictionary
- Python Functions
- Python Files I/O
- Read Write Excel
- Read Write JSON
- Read Write CSV
- Python OS Module
- Python Exceptions
- Python Datetime
- Python Collection Module
- Python Sys Module
- Python Decorator
- Python Generators
- Python OOPS
- Python Numpy Module
- Python Pandas Module
- Python Sqlite Module
Functions/Methods of the sys Module
- sys.argv – Command-Line Arguments:
The argv list contains command-line arguments passed to the script.
import sys
print("Script name:", sys.argv[0])
print("Arguments:", sys.argv[1:])
- sys.path – Module Search Path:
The path list contains directories where Python searches for modules.
import sys
print("Module search paths:")
for path in sys.path:
print(path)
- sys.version – Python Version Information:
The version string provides information about the Python interpreter.
import sys
print("Python version:", sys.version)
- sys.platform – Operating System Platform:
The platform string indicates the operating system platform.
import sys
print("Operating system platform:", sys.platform)
- sys.getsizeof() – Object Size in Memory:
The getsizeof() function returns the size of an object in bytes.
import sys
size = sys.getsizeof("Hello, world!")
print("Size of the string:", size, "bytes")
- sys.exit() – Graceful Exit:
The exit() function terminates the program with an optional exit code.
import sys
print("Exiting the program")
sys.exit(0)
- sys.maxsize – Maximum Integer Value:
The maxsize integer represents the maximum size of a list or range.
import sys
print("Maximum list size:", sys.maxsize)
- sys.modules – Loaded Modules:
The modules dictionary contains information about loaded modules.
import sys
print("Loaded modules:")
for module in sys.modules:
print(module)
- sys.exc_info() – Exception Information:
The exc_info() function returns information about the current exception.
import sys
try:
result = 1 / 0
except:
exc_type, exc_value, exc_traceback = sys.exc_info()
print("Exception type:", exc_type)
print("Exception value:", exc_value)