Learn Python – Python sys module- Basic and advance

The python sys module offers functions and variables which are used to manipulate extraordinary parts of the Python Runtime Environment. It lets us get right of entry to system-specific parameters and functions.

import sys

First, we have to import the sys module in our application before walking any functions.

sys.modules

This feature provides the identify of the current python modules which have been imported.

sys.argv

This feature returns a listing of command line arguments handed to a Python script. The title of the script is continually the item at index 0, and the relaxation of the arguments are saved at subsequent indices.

sys.base_exec_prefix

This feature presents an efficient way to the identical fee as exec_prefix. If no longer jogging a digital environment, the price will continue to be the same.

sys.base_prefix

It is set up at some point of Python startup, earlier than site.py is run, to the identical price as prefix.

sys.byteorder

It is an indication of the native byteorder that offers an environment friendly way to do something.

sys.maxsize

This feature returns the largest integer of a variable.

sys.path

This feature suggests the PYTHONPATH set in the current system. It is an surroundings variable that is a search direction for all the python modules.

sys.stdin

It is an object that contains the unique values of stdin at the start of the program and used during finalization. It can repair the files.

sys.getrefcount

This characteristic returns the reference rely of an object.

sys.exit

This feature is used to exit from both the Python console or command prompt, and additionally used to exit from the software in case of an exception.

sys executable

The value of this feature is the absolute route to a Python interpreter. It is beneficial for understanding where python is established on someone else machine.

sys.platform

This fee of this function is used to become aware of the platform on which we are working.