python模块
模块是函数功能的扩展,模块是可以实现一项或多项功能的程序块。
如何导入模块
在Python中在一个程序中要使用某个模块
import math
print math.pi
认识Python模块--sys模块
在Python中有一些模块是不用我们自己去定义,Python官方提供自带的模块,这些模块伴随Python的安装而产生,我们把这些模块叫做标准库模块。标准库模块是一类模块,而不是特指某种模块。
import sys
print sys.version
print sys.executable
print sys.getwindowsversion()
print sys.modules.keys()
输出:
2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)]
C:\Python27\python.exe
sys.getwindowsversion(major=6, minor=2, build=9200, platform=2, service_pack='')
['copy_reg', 'sre_compile', 'locale', '_sre', 'functools', 'encodings', 'site', '__builtin__', 'sysconfig', 'operator', '__main__', 'types', 'encodings.encodings', 'encodings.gbk', 'abc', '_weakrefset', 'encodings._codecs_cn', 'errno', 'encodings.codecs', 'sre_constants', 're', '_abcoll', 'ntpath', '_codecs', 'encodings._multibytecodec', 'nt', '_warnings', 'genericpath', 'stat', 'zipimport', 'encodings.__builtin__', 'mpl_toolkits', 'warnings', 'UserDict', '_multibytecodec', 'sys', 'codecs', 'os.path', '_functools', '_codecs_cn', '_locale', 'signal', 'traceback', 'linecache', 'encodings.aliases', 'exceptions', 'sre_parse', 'os', '_weakref']