One, OS module
Import OS, sys
Os.system (' ipconfig ') #执行操作系统命令, get no results returned
Os.popen () #也可以执行操作系统命令, can return command execution result, but need read out
Print (Os.popen (' dir '). Read ())
Second, sys module
Print (SYS.ARGV) #命令行参数List, the first element is the path of the program itself, the parameters that are entered when the file is executed
Example: Writing the input to a file
Inpu = sys.argv#gets all parameters passed in when the Pyth file is runifLen (INPU) >2: FileName= Inpu[1]#getting the first value in the list is the path to the execution file, and the second Inpu "1" is the file name,Conent = inpu[2]#The third input "2" is the command enteredopen (filename,'W', encoding='Utf-8'). Write (conent)Else: Print('parameter passed in error, e.g \ n' 'python test2.py filename content')
Sys.exit (n) exit program, Exit normally (0)
Print (sys.version) #获取Python解释程序的版本信息
Sys.maxint the largest int value
Sys.path Returns the search path for the module, using the value of the PYTHONPATH environment variable when initializing
Sys.platform returns the operating system platform name
Sys.stdout.write (' please: ') #向屏幕输出一句话
val = Sys.stdin.readline () [: -1] #获取输入的值
Python basic-os, sys module