论python常见内置模块
系统的内置模块
sys
hashlib
hmac
base64
time
datetime
sys模块:
sys.argv() 在Python脚本传参使用
sys.exit() 系统退出
sys.getdefaultencoding() 获取系统默认编码
getfilesystemencoding() 获取文件编码
getrecursionlimit() 获取系统默认递归的最大层数
setrecursionlimit(num) 设置递归的最大层数
getrefcount() 获取对象的引用计数的数量
hashlib:
base64模块
time模块:
asctime() # 获取系统当前时间
ctime() # 获取系统当前时间
time() # 获取当前的时间戳
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”)
时间戳(timestamp) :通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量。我们运行“type(time.time())”,返回的是float类型。
格式化的时间字符串
元组(struct_time) :struct_time元组共有9个元素共九个元素:(年,月,日,时,分,秒,一年中第几周,一年中第几天,夏令时)