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
On this page of the site you can watch the video online sys module in python with a duration of hours minute second in good quality, which was uploaded by the user Tarun Sir 02 May 2020, share the link with friends and acquaintances, this video has already been watched 30,673 times on youtube and it was liked by 436 viewers. Enjoy your viewing!