sys module in python

Veröffentlicht am: 02 Mai 2020
auf dem Kanal: Tarun Sir
30,673
436

In this video you will learn about various variables and functions of sys module in python.

sys module python

The sys module is a built in module in python. It provides several functions and variables to manipulate the python runtime environment. To use its functions we have to import it. The commonly used functions and variables of sys module are as follows:
• exit(): This function is used to terminate a program when needed. It can also be used to exit from the python terminal.
import sys
print("Hello World")#prints Hello World
sys.exit()#Terminate program here
print("Bye World")#It will not run

• path: This variable shows the value of PYTHON PATH environment variable which is set in the current system.
import sys
print(sys.path)#prints path, where the python modules are searched.

• platfom: This variable is used to identify the host operating system which we are using.
import sys
print(sys.platform)#prints os name

• executable : This specifies the path of python executable file.
import sys
print(sys.executable)#prints python executable’s path

• modules: Returns the list of available modules.
import sys
print(sys.modules)#prints all modules

• copyright : This shows the copyright info.
import sys
print(sys.copyright)#prints copyright info

• argv : This is actually a list which stores the command line arguments. The command line arguments or CLA are the parameters which are passed from command prompt while executing a python program. They are similar to command line arguments of C/C++/Java.
import sys
for x in sys.argv:
print(x)
The first command line argument is the name of the python file itself.

Besides the above, the sys module also provides various properties like stdin, stdout, and stderr that can be used to redirect the standard input, output and error streams. You can find out complete details on following page:
https://docs.python.org/3/library/sys...


#python_by_tarun_sir #tarun_sir #python #tarun_sir_python #python_video_58 #sys_module_in_python #python_tutorial #command_line_arguments_in_python #exit_function_in_python


Auf dieser Seite können Sie das Online-Video sys module in python mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Tarun Sir 02 Mai 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 30,673 Mal angesehen und es wurde von 436 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!