'''
OS模块
目录
.removedirs(dirname)
.makedirs(dirname)
.mkdir(dirname)
.rmdir(dirname)
.chdir(dianme)
.listdir(diranme)
文件
.remove(filename)
文件/目录
.rename(oldaname, newname)
.stat(path)
系统
os.getcwd()
os.getppid()
.getpid()
.cpu_count()
属性
.environ
.sep
.pathsep ; :
.name
.linesep \r\n \n
执行命令
.system()
.popen().read()
os.path
分割
.abspath()
.split()
.dirname()
.basename()
.splitext()
判断
isabs()
isfile()
isdir()
exists()
合并
.join(os.path.abspath(), path)
获取
.getatime()
.getmtime()
.getctime()
.getsize()
stat
st_uid
st_gid
st_size
st_atime
st_mtime
st_ctime
sys模块
属性
sys.path
sys.version
sys.platform
sys.stdin
sys.stdout
sys.stderr
方法
sys.argv[]
sys.exit()
time模块
timestamp --> format string
ctime
--> struct_time
localtime
gmtime
struct_time --> timestamp
mktime
format string --> struct_time
strptime
struct_time --> format string
strftime
asctime
time.time()
time.sleep()
struct_time
tm_year mon mday hours min sec yday wday
format string
%Y %m %d %H %M %S
datetime模块
datetime(year, month, day, hours, minutes, seconds)
.now()
.today()
.utcnow()
date(year, month, day)
.today()
time(hours, minutes, seconds)
日期对象
.year
.month
.day
.weekday
.isoweekday
timedelta对象
日期对象 + - 日期对象 = timedelta对象
日期对象 + - timedelta对象 = 日期对象
random模块
random()
randint(a, b)
uniform(a, b)
randrange(start, stop ,step)
choice([obj,...])
sample([obj,..], int)
shuffle(list)
math模块
fabs()
ceil()
floor()
pi
sin()
cos()
tan()
pow(a ,b)
factorial()
json模块
dumps(obj)
loads(json)
dump(obj, file)
load(file)
pickle模块
dumps(obj)
loads(pickle)
dump(obj ,file)
load(file)
csv模块
.writer(file)
.wirterow([])
wirterows([[],[]])
.reader(file)
list(reader(file))
struct模块
pack(mode, date)
unpack(mode. data)
collections
namedtuple
可以给元组中每个元素附加额外的字段名,可以通过字段名来获取对于元素值
a = namedtuple('a', 'name age height')
b = a('zhangsan', 18, 180)
b.name b[0]
b.age b[1]
b.height b[2]
deque
提高列表插入和删除操作的效率,适用于队列和栈
a = deque(iterable)
a.append()
a.pop()
a.appendleft()
a.popleft()
OrderedDict()
有序字典
a = OrderedDict(**kwargs,[(k,v),...])
defaultdict(func, **kwargs, [(k,v),...])
key不存在返回默认值,不会报错
Counter(iterable)
以列表的形式,返回iterable中元素出现个数,对于字典则鸳鸯返回
hashlib模块
hexdigest
hashlib
configparser模块
对 ini文件的增删改查
基本三板斧
config = configparser.ConfigParser()
config.read('.ini', encoding='')
config.write(open())
创建
config['section'] = {'option': 'value',...}
增加section
.add_setion('section')
删除
.remove_section('section')
.remove_option('section', 'option')
修改option
.set('section' ,'option', 'value')
查看
[section][option]
.sections()
.options('section', 'option')
.get('section', 'option')
getint
getfloat
getboolean
items('section') [(option, value),...]
判断
has_section('section')
has_option('section', 'option')
io模块
StringIO
.write(str)
.getvalue()
.close()
BytesIO
.write(byte)
.getvalue()
.close()
'''