zoukankan      html  css  js  c++  java
  • Python常用库

    A .标准库, time  datetime  两个标准库
    1.time 与 datetime 1)时间戳 2)格式化时间 3)元祖 (struct_time)共九个元素,time.localtime() 元组数据

    UTC 格林威治时间 中国 UTC+8 比标准时间早八个小时


    time() 获取时间戳
    gmtime() 将时间转为UTC时区的时间
    localtime() 当前时间戳转为元组。或传进来的时间戳的元组信息

    时间戳
    时间戳转为元组 gmtime( time ) --> utc时区
    localtime( time ) --> 当前时区

    元组转时间戳 mktime( time ) 将元组转为时间戳


    将元组转为格式化字符串 strftime( '%Y-%m-%d',(元组时间))
    将时间格式 转为元祖 strptime( "2017-07-16","时间格式") 返回一个时间元组

    asctime(接受元组数据) ctime(传入的是时间戳)


    datetime.datetime.now()获取当前时间 与datetime.timedelta(3) 同时使用获当前时间对应的3天 —+3 或者是hours=3
    计算前三天 或前三个小时,三年 ,等等


    B random 随机浮点标准库



    C os模块
    os.getcwd() 获取当前工作目录,
    os.chdir("cc") 改变当前脚本工作目录

    D sys 系统模块
    pring(sys.argv 1234) 获取参数

    E shutil 文件操作模块

    F json pickle 模块
    json 主要进行序列化 用户字符串和python 数据类型间的转换
    dumps dump loads load
    pickle功能dumps dump loads load python特有的模块
    G shelve 模块 ,简单的kv 将内存数据通过文件持久化的模块 ,可以持久化任何pickle可支持的python数据格式


    H XML 处理模块
    import xml.etree.ElementTree as ET 引入xml处理模块

        吾之爱,心之念。
               携子手,到白头。

  • 相关阅读:
    Codeforces Round #644 (Div. 3)(A~G)
    【】BZOJ3687: 简单题(dp+bitset)
    [LeetCode] 275. H-Index II
    [LeetCode] 1028. Recover a Tree From Preorder Traversal
    [LeetCode] 1014. Best Sightseeing Pair
    [LeetCode] 468. Validate IP Address
    [LeetCode] 701. Insert into a Binary Search Tree
    [LeetCode] 658. Find K Closest Elements
    [LeetCode] 787. Cheapest Flights Within K Stops
    [LeetCode] 1300. Sum of Mutated Array Closest to Target
  • 原文地址:https://www.cnblogs.com/JC-0527/p/7190613.html
Copyright © 2011-2022 走看看