'''
datetime
datetime是Python处理日期和时间的标准库
'''
from datetime import datetime
now = datetime.now()
print(now)
print(type(now))
dt = datetime(2015, 4, 19,12, 30)
print(dt)
print(dt.timestamp())
t = 12343534.0
print(datetime.fromtimestamp(t))
print(datetime.utcfromtimestamp(t))
cday = datetime.strptime('2015-6-1 18:19:59', '%Y-%m-%d %H:%M:%S')
print(cday)
now = datetime.now()
print(now.strftime('%a, %b %d %H:%M'))
'''
collections
collections是Python内建一个集合模块,提供了许多有用的集合类
'''
from collections import namedtuple
Point = namedtuple('Point', ['x', 'y'])
p = Point(1,2)
print(p.x)
print(p.y)
from collections import deque
q = deque(['a', 'b', 'c'])
q.append('x')
q.append('y')
print(q)
from collections import defaultdict
dd = defaultdict(lambda : 'N/A')
dd['key1'] = 'abc'
print(dd['key1'])
print(dd['key2'])
from collections import OrderedDict
d = dict([('a', 1), ('b', 2), ('c', 3)])
print(d)
od = OrderedDict([('a', 1), ('b', 2), ('c', 3)])
print(od)
from collections import Counter
c = Counter()
for ch in 'programming':
c[ch] = c[ch] +1
print(c)
'''
urllib
urllib提供一系列用于操作URL的功能
'''
from urllib import request
with request.urlopen("https://api.douban.com/v2/book/2129650") as f:
data = f.read()
print('Status:', f.status, f.reason)
for k, v in f.getheaders():
print('%s: %s' % (k, v))
print('Data:', data.decode('utf-8'))
更多精彩内容访问个人站点www.gaocaishun.cn