Home » Python sys module

Python sys module

by maxguy71

The sys module provides functions and variables used to manipulate different parts of the Python runtime environment.

Usage

First, we have to import the sys module in our program before running any functions.

import sys

Functions

sys.modules

This function returns the name of the Python modules that the current shell has imported.

sys.argv

This function returns a list of command line arguments passed to a Python script. The name of the script is always the item at index 0, and the rest of the arguments are stored at subsequent indices.

sys.base_exec_prefix

This function provide a way to the same value as exec_prefix. If not running a virtual environment, the value will remain the same.

sys.base_prefix

This is set during Python startup, before site.py is run, to the same value as prefix.

sys.byteorder

It is an indication of the native byteorder that provides an efficient way to do something.

sys.maxsize

This function returns the largest integer of a variable.

sys.path

This function shows the PYTHONPATH set in the current system. It is an environment variable that is a search path for all the python modules.

sys.stdin

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

sys.getrefcount

This function returns the reference count of an object.

sys.exit([arg])

This can be used to exit the program. The optional argument arg can be an integer giving the exit or another type of object. If it is an integer, zero is considered “successful termination”.

sys executable

The value of this function is the absolute path to a Python interpreter. It is useful for knowing where python is installed on someone else machine.

sys.platform

This value of this function is used to identify the platform on which we are working.

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More