Application of python3.7 sys Module
- 2021-07-24 11:14:30
- OfStack
The sys module of Python provides access to variables used or maintained by the interpreter and functions to interact with the interpreter. Generally speaking, the sys module is responsible for the interaction between the program and the python interpreter, and provides a series of functions and variables for controlling the environment of python runtime.
#!/usr/bin/env python
__author__ = "lrtao2010"
#python3.7 sys Module
#sys Module is responsible for program and python The interaction of the interpreter, which provides the 1 Series of functions and variables,
# Used for manipulation python The environment of the runtime.
# sys.argv Receives command line arguments, generates 1 A List , No. 1 Elements are the path of the program itself
# sys.modules.keys() Returns a list of all modules that have been imported
# sys.exc_info() Gets the exception class currently being handled ,exc_type , exc_value , exc_traceback Exception details currently handled
# sys.exit(n) Exit the program, when exiting normally exit(0)
# sys.hexversion Get Python Interpret the version value of the program, 16 The binary format is as follows: 0x020403F0
# sys.version Get Python Interpret the version information of the program
# sys.maxint Maximum Int Value
# sys.maxunicode Maximum Unicode Value
# sys.modules Returns the module field imported by the system, key Is the module name, value Is a module
# sys.path Returns the search path of the module, which is used when initializing PYTHONPATH Values of environment variables
# sys.platform Returns the operating system platform name
# sys.stdout Standard output
# sys.stdin Standard input
# sys.stderr Error output
# sys.exc_clear() Used to clear the current or recent error message of the current thread
# sys.exec_prefix Returns platform-independent python Location where files are installed
# sys.byteorder Indicator of the local byte rule, big-endian The value of the platform is 'big',little-endian The value of the platform is 'little'
# sys.copyright Record python Copyright-related things
# sys.api_version Interpreter's C Adj. API Version
# import sys
# my_sys = sys.argv
# for i in my_sys:
# print(i)
# >>>python sys_module.py test test1 test2
# sys_module.py
# test
# test1
# test2
# print(sys.path)
# print(__name__)
# print(__file__)
#
# __main__
# sys_module.py
#import sys,os
# print(os.path.abspath(__file__))
# E:\python\learning\app\Module_and_Functions\sys_module.py
#print(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# from method import test
# test.test()
# ModuleNotFoundError: No module named 'method'
# Dynamic modification sys.path Variable
# BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# sys.path.append(BASE_DIR)
# from method import test
# test.test()
#
# This is test
# Real-time printout
# import time,sys
# for i in range(20):
# sys.stdout.write("=")
# time.sleep(0.5)
# sys.stdout.flush() # Screen refreshed from cache