常用的库
右键:包 -> Mark Ddirectory as -> S / E / R / T
import sys
# 自身运行环境 sys
'''
右键 包 -> Mark Ddirectory as -> S / E / R / T
'''
for p in sys.path:
# 导包路径
print(p)
print(sys.version)
print(sys.argv) # 得到 运行程序时 传入的参数
# 命令行运行 + 传入参数 python [xxx.py a 100] 括号内的都被sys.argv保存
# pycharm 传入参数 右上角: Run/Debug Configurations -> Parameters 设置
print(sys.version_info)
import time
# 时间 time
ot = time.time() # 时间戳
print(ot)
time.sleep(0.1)
# 时间戳 -> 字符串
st = time.ctime()
print(st)
# 时间戳 -> 元组
yt = time.localtime()
print('今天周{}'.format(yt.tm_wday + 1))
# 元组 - > 时间戳
sjc = time.mktime(yt)
print(sjc)
# 时间戳[/元组] - 格式化 -> 字符串
sf = time.strftime('%Y-%m-%d', yt)
print(sf)
# 格式化字符串 -> 元组
fs = time.strptime('2019/11/16', '%Y/%m/%d')
print(fs)
import datetime
# datetime
d = datetime.date(2019, 11, 16)
print(d.ctime())
print(d.strftime('%Y/%m/%d'))
dt = datetime.timedelta(days=1, minutes=30, hours=2, seconds=59) # delta时间差 δ Δt
print(dt)
now = datetime.datetime.now() # 得到当前的时间对象
print(now)
print(now + dt)
# redis 做缓存时,通过 δ 时间差 控制
# session 会话机制, 内存缓存
import random
# random
r = random.random() # 0-1 之间的随机小数
r_int = random.randint(1, 12) # 包含 [a,b]
r_r = random.randrange(1, 12, 2) # 1,3,5,7,9,11 中间 产生随机数 (a,b,s) [a,b)
r_c = random.choice(['jam', 'lst', 'czz', 'lmd']) # 在列表中随机选择
print(r, r_int, r_r, r_c)
r_l = [x for x in range(10)]
print(r_l)
random.shuffle(r_l)
print(r_l)
# 标准库
# unicode -> str
print(chr(65))
# str -> unicode
print(ord('操'))
# 加密
import hashlib
"""
加解密 都不能直接操作
需要encoded 和 decode 操作
md5 sha1 均是单向加密 无法解密
base64加密 双向 加解密
"""
msg = '这是一个机密'
e_msg = msg.encode('utf-8')
print(e_msg)
m_msg = hashlib.md5(e_msg)
print(m_msg.hexdigest()) # 十六进制显示
s_msg = hashlib.sha256(e_msg)
print(s_msg.hexdigest())