Sys Module with Examples in Python
Tags: python
Published: 2020-06-09 12:49:06

The <a href="https://docs.python.org/3/library/sys.html">sys module</a> has access to some variables used by the interpreter. 

In this article you'll see some sys module examples in the Python programming language.  

## Python sys Module

The **sys** module provides you with details about the Python interpreter. Note that if you want to do things with the operating system like <a href="https://python-commandments.org/python-system-command/">running a program</a> you can use the os module instead.

This module is one of the best Python modules, and if you want to use the sys module, you need to import it into the program like other built-in modules.

![python sys module](https://dev-to-uploads.s3.amazonaws.com/i/dielymxsanhcj47wzbs9.png)

This provides a lot of *information about the Python interpreter*, such as the version of the interpreter, the maximum value that the <a href="https://pythonspot.com/python-variables/">variable</a> can hold, the copyright information of the Python interpreter, etc.

Here, with an example, you can see some important functions of the **sys** module. 

You can try this from both the <a href="https://bsdnerds.org/learn-python/">shell</a> and from a <a href="https://pythonbasics.org/execute-python-scripts/">script</a>.

Important functions of the sys module are shown below.

### 1) sys.version

This function returns the version of the Python interpreter in <a href="https://pythonbasics.org/strings/">string</a> format with the date of the installation.

**Python Example:**    

```python    
    # Importing the module
    import sys
    
    # Printing the python version
    print(sys.version)
```    

The program above outputs this:    
    
    3.7.7 (default, Mar 13 2020, 10:23:39) \n[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)]
    

### 2) sys.copyright

This function returns information about the copyright of the Python interpreter.

**Python Example:**    

```python    
    # Importing the sys module
    import sys
    
    # Printing copyright info
    print('Information about copyright:')
    print(sys.copyright)
```    

The program above outputs this:    
    
    'Copyright (c) 2001-2020 Python Software Foundation.\nAll Rights Reserved.\n\nCopyright (c) 2000 BeOpen.com.\nAll Rights Reserved.\n\nCopyright (c) 1995-2001 Corporation for National Research Initiatives.\nAll Rights Reserved.\n\nCopyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.\nAll Rights Reserved.'
    

### 3) sys.maxsize

This function returns the maximum value of int that a variable can take.

**Python Example:**    

```python    
    # Importing the sys module
    import sys
    
    # Printing the max value of an int
    print('Maximum value of an int:',sys.maxsize)
```    

The program above outputs this:    
    
    Maximum value of an int: 9223372036854775807
    

### sys.path

This function returns a <a href="https://pythonprogramminglanguage.com/lists/">list</a> which includes all Python modules in the search path. 

**Python Example:**    
   
```python 
    # Importing the sys module
    import sys
    
    # Printing the all path
    print('List of the all paths:')
    print(sys.path)
```    

The program above outputs this:    
    
    List of the all path: ['/home/frank', '/usr/lib64/python37.zip', '/usr/lib64/python3.7', '/usr/lib64/python3.7/lib-dynload', '/home/frank/.local/lib/python3.7/site-packages', '/home/frank/.local/lib/python3.7/site-packages/tpass-0.1.8-py3.7.egg', '/home/frank/.local/lib/python3.7/site-packages/simplejson-3.17.0-py3.7.egg', '/home/frank/.local/lib/python3.7/site-packages/pyperclip-1.8.0-py3.7.egg', '/usr/lib/python3.7/site-packages', '/usr/lib64/python3.7/site-packages']
    
**Read more**
* <a href="https://gumroad.com/l/dcsp">Python Crash Course for Beginners</a>
* <a href="https://docs.python.org/3/library/sys.html">Python sys module</a>