Python's strength is that he has a very rich and powerful standard library and third-party library, almost any function you want to implement has the corresponding Python library support, later in the course will be in depth to explain the various libraries commonly used, now, we first to symbolically learn 2 simple.
#sys
#!/usr/bin/env python#-*-coding:utf-8-*-import sys print (SYS.ARGV) #输出 $ python test.py helo world[' test.py ', ' helo ', ' World ' #把执行脚本时传递的参数获取到了
#os
#!/usr/bin/env python#-*-coding:utf-8-*-import os os.system ("Df-h") #调用系统命令
Completely combine:
Import Os,sys Os.system ('. Join (sys.argv[1:])) #把用户的输入的参数当作一条命令交给os. System to perform
Write a module yourself:
import sysimport readlineimport rlcompleterif sys.platform == ' Darwin ' and sys.version_info[0] == 2: Readline.parse_and_bind ("Bind ^i rl_complete") Else: readline.parse_and_bind (" Tab: complete ") # linux and python3 on macfor mac
#!/usr/bin/env Python # python startup file import sysimport readlineimport rlcompleterimport atexitimport os# tab complet Ion Readline.parse_and_bind (' Tab:complete ') # history file Histfile = Os.path.join (os.environ[' HOME '), '. pythonhistory ') Try:readline.read_history_file (histfile) except IOError:passatexit.register (Readline.write_history_file, Histfile) del os, Histfile, ReadLine, Rlcompleterfor Linux
After you've written it, you can use it.
localhost:~ jieli$ Pythonpython 3.5.2 (default, OCT, 18:05:06) [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0. 59.5)] on Darwintype ' help ', ' copyright ', ' credits ' or ' license ' for more information.>>> import tab
you will find that the above-written tab.py module can only be imported in the current directory, if you want to use the system where and how to do it? At this point, you're going to put this tab.py in the Python Global environment variable directory, basically put in a callpython/2.7/site-packages directory, this directory does not have the same location in different OS, and print(sys.path) allows you to view a list of Python environment variables.
This article is from the "Little Rookie" blog, please be sure to keep this source http://baishuchao.blog.51cto.com/12918589/1933582
Python module initial