sys module in python

Publicado em: 02 Maio 2020
no canal de: 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


Nesta página do site você pode assistir ao vídeo on-line sys module in python duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Tarun Sir 02 Maio 2020, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 30,673 vezes e gostou 436 espectadores. Boa visualização!