在Pyhton中,除了上篇写到的os和os.path模块外,
还有几个是我们在Python中常用到的内置模块。
一.sys模块
1.sys.argv() 在python脚本传参使用
2.sys.exit() 系统退出
3.sys.getdefaultencoding() 获取系统默认编码
4.sys.getfilesystemencoding() 获取文件编码
5.sys.getrecursionlimit() 获取系统默认递归的最大层数
6.sys.setrecursionlimit(num) 设置递归的最大层数
7.sys.getrefcount() 获取对象的引用计数的数量
二.hashlib模块:
加密,散列加密(hash加密)
加密是否可逆:
1.可逆加密:根据加密和解密的密钥是否是同一个
2.对称加密:DES
3.非对称加密:RSA
4.不可逆加密:hash是典型的不可逆加密(MD5、shal256)
使用:
import hashlib
md5 = hashlib.md5("需要加密的数据".encode("utf-8"))
可以看到数字123456789加密完成。
三.base64模块
1.b64encode()
用此方法来完成一串字符的加密
2.b6decode()
用此代码去解密一个用b64encode加密过的字符串
四.time模块:
1.asctime() 获取系统当前时间
2.ctime() 获取系统当前时间
3.time() 获取当前的时间戳
4.localtime() 返回当前时间,以类似于元组的对象
5.t = time.localtime()
print(“当前时间是%s-%s-%s %s:%s:%s” %(t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec))
time.strftime() # 将时间对象格式化成字符串
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
6.time.strptime() # 时间字符串转换为时间对象
time.strptime(‘2019/09/18 21:02:44’, “%Y/%m/%d %H:%M:%S”)
五.datetime模块
datetime.datetime.now() # 获取系统当前时间