Python--day19--sys module

sys module

The sys module is an interface for interacting with the python interpreter

sys.argv command line parameter list, the first element is the path of the program itself
sys.exit(n) Exit the program, exit(0) when exiting normally, exit sys.exit(1) with error
sys.version Get the version information of the Python interpreter
sys.path returns the search path of the module, using the value of the PYTHONPATH environment variable during initialization
sys.platform returns the OS platform name
1 import sys
2 try:
3     sys.exit(1)
4 except SystemExit as e:
5     print(e)
Exception handling and status

sys.platform returns the OS platform name

sys.argv command line parameter list, the first element is the path of the program itself

Example 1: (execute in terminal, if executed in pycharm, an error will be reported)

Example 2:

Executing in pycharm will report an error: