The power of Python is that he has a very rich and powerful library of standards and third-party libraries, and almost any feature you want to implement has the appropriate Python library support
1. Standard library
Python has a lot of standard libraries, we first know the SYS and OS modules, because these two modules in the development of the most
①sys
SYS module Operation module search path, use SYS module to find built-in module, use SYS module to find imported modules, etc.
| 12345678910111213141516171819 |
#! /usr/bin/env python# -*- coding:utf-8 -*-# __auther__ == zhangqigaoimportsysprint(sys.argv)#打印的是模块本身的相对路径#输出$ python test.py helo world[‘test.py‘, ‘helo‘, ‘world‘] #把执行脚本时传递的参数获取到了print(sys.path)#输出Python的执行路径#输出[‘D:\\PycharmProjects\\pyhomework\\day2‘, ‘D:\\PycharmProjects\\pyhomework‘,‘D:\\Python\\Python35\\python35.zip‘, ‘D:\\Python\\Python35\\DLLs‘,‘D:\\Python\\Python35\\lib‘, ‘D:\\Python\\Python35‘, ‘D:\\Python\\Python35\\lib\\site-packages‘]#其中 ‘D:\\Python\\Python35\\lib\\site-packages‘ 是第三方库安装的路径 |
②os
OS, the semantics of the operating system, so it must be operating system-related functions, can handle files and directories that we need to do daily manual operations
| 12345678910111213 |
#! /usr/bin/env python# -*- coding:utf-8 -*-# __auther__ == zhangqigaoimportoscmd_reslut =os.system("dir")print(cmd_reslut)#输出#命令被执行,执行完成后会返回一个状态:0表示执行成功,其他数字表示执行失败cmd_reslut =os.popen("dir").read()print(cmd_reslut)#输出#命令被执行,且执行后的结果返回出来 |
③ two A perfect combination
| 123456 |
#! /usr/bin/env python# -*- coding:utf-8 -*-# __auther__ == zhangqigaoimportsys,osos.system(‘‘.join(sys.argv[1:]))#把用户的输入的参数当作一条命令交给os.system来执行 |
2. Third-party libraries
Python In addition to the standard library, there are other third-party libraries, third-party libraries directly download the installation, download and install the third-party library is under D:\\python\\python27\\lib\\site-packages (where d:\\python\\ Python27 is your own path to install Python)
If you need to develop a third-party library, write your own modules, copy to D:\\python\\python27\\lib\\site-packages, and then directly import, the steps are as follows:
① Copy to D:\\python\\python27\\lib\\site-packages
②import import your own developed third-party libraries
Python base "day01": initial module