python常见内置模块

系统的内置模块
sys
hashlib
hmac
base64
time
datetime

ys模块:
|-- sys.argv() # 在Python脚本传参使用(很重要)
import sys
if len(sys.argv) <= 1:
print(“sorry, arguments is too short”)
else:
print(sys.argv)
print(sys.argv[1])
print(sys.argv[2])
|-- sys.exit() # 系统退出
整个程序直接退出
|-- sys.getdefaultencoding() # 获取系统默认编码
sys.getdefaultencoding()
‘utf-8’
|-- getfilesystemencoding() # 获取文件编码
|-- getrecursionlimit() # 获取系统默认递归的最大层数
getrecursionlimit()
1000
|-- setrecursionlimit(num) # 设置递归的最大层数
setrecursionlimit(2000)
getrecursionlimit()
2000
|-- getrefcount() # 获取对象的引用计数的数量

hashlib:
加密,散列加密(hash加密)
加密是否可逆:
|-- 可逆加密
根据加密和解密的秘钥是否是同一个
|-- 对称加密
DES
|-- 非对称加密
RSA

|-- 不可逆加密
hash是典型的不可逆加密
MD5、shal256
import hashlib
md5 = hashlib.md5(“需要加密的数据”.encode(“utf-8”))

import hashlib
md5 = hashlib.md5(“123456”.encode(“utf-8”))
md5.hexdigest()
e10adc3949ba59abbe56e057f20f883e

base64模块
|-- b64encode() # 查找资料,完成自学
|-- b64decode()

time模块:
|-- asctime() # 获取系统当前时间
import time
time.asctime()
‘Mon Sep 23 17:38:14 2019’

|-- ctime() # 获取系统当前时间
time.ctime()
‘Mon Sep 23 17:38:14 2019’

|-- time() # 获取当前的时间戳
1569231591.342605
|-- localtime() # 返回当前时间,以类似于元组的对象
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())
|-- time.strptime() # 时间字符串转换为时间对象
time.strptime(‘2019/09/18 21:02:44’, “%Y/%m/%d %H:%M:%S”)

calendar 日历模块 # 自学

datetime
|-- datetime.datetime.now() # 获取系统当前时间

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值