python13day
#############
import sys, pprint
sys.path.append(‘D:/pycharm_work’)
import day_7
dir(day_7)
import hell4
hell4.hello()
pprint.pprint(sys.path)#查找模块位置
import copy
print(dir(copy))#dir查看模块内容
print([n for n in dir(copy) if not n.startswith(’_’)])
print(copy.all)#查看所有内容,模块内容
help(copy.copy)
print(copy.doc)
help(copy)
print(copy.file)
sys模块
sys.stdin # 标准输入
sys.stdout # 标准输出
sys.stderr # 标准错误
sys.exit()#退出当前程序
os模块
import os
os.linesep # 用于文本文件的字符串分割
os.system # 用于执行外部程序
fileinput模块
import fileinput
fileinput.filename # 返回当前的文件名称
fileinput.lineno # 返回当前累计行数
fileinput.filelineno # 返回当前文件行数
fileinput.isfirstline # 检查当前文件是否文件第一行
fileinput.isstdin # 检查最后一行是否来自sys.stdin
fileinput.nextfile # 关闭当前文件关闭到文件下一个
fileinput.close # 关闭序列
集合,集合元素是随意的
a = set(range(10))
print(a)
b = set([1, 2, 3])
c = set([2, 3, 4])
print(b.union(©))
print(b | c) # 找出集合的并集
print(b & c) # 找出交集
print(c.difference(b))
堆,能够以任意顺序增加对象
import heapq
heapq.heappush # 将x入堆
heapq.heappop # 将堆中最小的元素弹出
heapq.heapreplace # 将堆中最小元素弹出,并将x入堆
heapq.heapify # 将heap属性强制应用到每个列表
heapq.nlargest # 返回第n大元素
heapq.nsmallest # 返回第n小的元素
双端队列,按元素增加的顺序,移除元素非常有用
from collections import deque
q = deque(range(5))
q.append(5)
q.appendleft(6)
q.pop()
q.popleft()
q.rotate(3) # rotate旋转元素
q.rotate(-1)
print(q)
time
import time
time.asctime # 将时间元组转换为字符串
time.localtime # 将秒数转换为日期元组,以本地时间为准
time.mktime # 将时间元组转换为本地时间
time.sleep # 休眠
time.strptime # 将字符串解析为时间元组
x = time.time() # 当前世界,从新纪元到现在的秒数
t = time.strftime(’%Y-%m-%d %H:%M:%S %j %U’)
print(t)
print(time.asctime(time.localtime(x)))
random
import random
print(random.random()) # 返回0-1的伪随机数
print(random.getrandbits(3)) # 以长整形式返回n个随机位
print(random.uniform(1, 10)) # 返回a-b之间的随机数
print(random.randrange(0, 10, 2))
random.choice # 从序列中随机返回任意元素
random.shuffle # 将给定的序列进行随机移位
random.choice # 从给定序列中,选择给定数目的元素
values = list(range(1, 11)) + list(‘Jack Queen King’.split())
suits = ‘dimaonds clubs hearts spades’.split()
deck = [’%s of %s’ % (v, s) for v in values for s in suits]
random.shuffle(deck)
print(deck[:15])
shelve
import shelve
s = shelve.open(‘test_3.bat’)
s[‘x’] = [‘n’, ‘m’, ‘h’]
print(s[‘x’])
- 8highlights for day 13 of Python
- Python Day13
- python Day13之局部,全局变量和递归函数
- 函数再学习(Python day 13)
- 每日积累(20161207-day-13)(python.os caffe-draw_net.py)
- Python 基础-项目实战-day 13 Android客户端开发(项目完结)
- PythonDay13
- python 自动化之路 day 13
- PYTHON_DAY_13_201606011
- Python学习笔记 Day 13 项目 -外星人入侵 - 1,pygame安装,OS X / Windows
- 13 highlights for day 8 of Python
- Python标准库13 循环器 (itertools)学习
- Python学习笔记 Day 15 项目 -外星人入侵 -3
- python学习笔记13:Qt Designer的安装方法
- day15 python css
- day13—HTML DOM编程
- 重学Python - Day 02 - python基础 -> if语句应用 + while循环应用
- Python Learning Note---Day 1
- 每日积累(20161130-day-8)(caffe-boost python-boost )
- python高级-异常(13)