论python常见内置模块

论python常见内置模块

1.系统的内置模块

Sys

Hashlib

Hmac

 

Sys模块

Sys.argv         在python脚本传参使用

Sys.exit          系统退出

       Sys.getdefaultencoding()     获取系统默认编码

       Getfilesystemencoding()      获取文件编码

       Getrecursionlimit()              获取系统默认递归的最大层数

       Setrecursionlimit(num)        设置递归的最大层数

       Getrefcount()                      获取对象的引用计数的数量

 

Hashlib(不可逆加密):

       加密,散列加密(hash加密)

       加密是否可逆:

              可逆加密(能还原回去)

                     根据加密和解密的密钥是否是同一个

                            对称加密

                                   DES

                            非对称加密

                                   RSA

              不可逆加密  

                     MD5、sha1256

Import hashlib

Dir(hashlib)

Base64模块

       B64encode           

       B64decode

以"*encode"结尾的方法用于将二进制串转为base64编码格式的字符串,以“*decode”结尾的方法用于将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")

 

Calendar 日历模块

import calendar

    calendar.calendar()   #返回指定的年的日历

  • w = 每个日期之间的间隔字符数
  • l = 每周所占用的行数
  • c = 每个月之间的间隔字符数

    calendar.month()   #获取某年某月的月日历字符串

    calendar.monthcalendar() 返回某年某月的月日历矩阵,每行代表一周

    calendar.monthrange() 返回指定月份第一天(即1号)的星期日期,和本月的总天数

    calendar.weekday() 返回指定日期所对应的星期日期

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

发布了35 篇原创文章 · 获赞 3 · 访问量 1697

猜你喜欢

转载自blog.csdn.net/qq_43773458/article/details/101038780