Python基础12 模块
模块和包
包就是文件夹,模块就是文件,每一个包下必须有一个__init__.py
文件导入模块
import math
math.pow(2,10)
math.pi
- 导入部分模块成员
from math import pow, sin, log
- 别名
from math import log
from logging import log as logger
- 动态导入模块
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
__future__
Python新版本中将引入的试用功能
from __future__ import division
print 10 / 3
在Python 2.7中引入3.x的除法规则