<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      6. Python 模塊

      模塊其實就是一個python文件
      python導入模塊的順序
      1. 從當前目錄下找需要導入的python文件
      2. 從python的環境變量中找 sys.path
      當前目錄和sys.path中都有import文件時,優先看當前目錄的python文件。
      1、標準模塊(標準包):python自帶的模塊,直接import就能用的
      string , random ,datetime ,os, json
      2、第三方模塊,別人寫好的一些模塊,要安裝之后才可以用
      1)傻瓜式安裝
      pip install pymysql
      2)手動安裝
      到百度搜索安裝包,如安裝redis.
       
      whl結尾的安裝包
      下載完成后,在下載文件夾的地址欄中輸入cmd,即可打開當前目錄命令行,輸入命令:pip install redis-2.10.6-py2.py3-none-any.whl
      .tar.gz結尾的安裝包
      如果是下載的redis-2.10.6.tar.gz,解壓后,進入目錄,在地址欄輸入cmd
      在命令行運行:python setup.py install
       
      3、自己寫的python文件,當作一個模塊來引用
       
       
      random模塊
      import random,string
      print(string.printable) #代表 數字+字母+特殊字符
      print(random.randint(1,100)) #隨機取整數
      print(round(random.uniform(1,99),2)) #取隨機小數,加round取2位小數
      print(random.choice([1,2,3,4])) #只能隨機取1個元素
      print(random.sample(string.printable,5)) #隨機取N個元素,返回的是list
      #洗牌
      pickts = ['A','J','Q','K',2,3,4,5,6]
      random.shuffle(pickts) #只能傳list
      print(pickts)
       
       
      json模塊
      json串格式校驗:http://www.bejson.com
      1、json串 轉成一個字典:load
      import json
      #json串是一個字符串
      f = open('product.json',encoding='utf-8')
      res = f.read() #用json.loads()要先讀一次,變成字符串
      product_dic = json.loads(res) #json.loads() 只能傳一個字符串,把json串變成python的數據類型:字典
      print(type(product_dic)) #已轉換成字典類型
      print(product_dic)
      print(product_dic.get('product_info'))
       
      import json
      #json串是一個字符串
      f = open('product.json',encoding='utf-8')
      print(json.load(f)) #只傳一個文件對象,自動讀取文件,直接操作文件
       
      2、字典轉換一個json串:dump
       
      d = {
      "iphone":{
      "color":"red",
      "num":1,
      "price":98.5
      },
      "wather":{
      "num":100,
      "price":1,
      "color":"white"
      }
      }
       
      import json
      fw = open('product.json', 'w', encoding='utf-8')
      dic_json = json.dumps(d, ensure_ascii=False, indent=4) #字典轉換成json,變成字符串,ensure_ascii=False 顯示中文,INDENT = indent = 4
      fw.write(dic_json)
       
      也可以寫成:
      import json
      fw = open('product.json', 'w', encoding='utf-8')
      json.dump(d,fw,ensure_ascii=False,indent=4)
       
      dump是直接對文件進行操作,dumps是對字典進行操作
       
      時間模塊
      #時間戳:
      #1. 從unix元年到現在過了多少秒
      #2.格式化好的時間
      import time
      print(time.time())
      # time.sleep(1)
      today = time.strftime('%Y-%m-%d %H:%M:%S')
      # today = time.strftime('%y-%m-%d %H:%M:%S')
      print(today)
       
      #時間戳 轉換 時間:
      # 1. 要先轉換成時間元組
      #2.再把時間元組轉成成格式化的時間
      print(time.gmtime()) #默認取的是標準時區的時間,不傳時默認標準時區的時間戳
      print(time.localtime()) #默認取的是當前時區的時間,不傳時默認當前時區的時間戳
      s = time.localtime(1524299155)
      print(time.strftime('%Y-%m-%d %H:%M:%S',s))
       
      時間戳轉換格式化時間的函數
      def timestamp_to_fomat(timestamp = None,format = '%Y-%m-%d %H:%M:%S'):
      if timestamp:
      time_tuple = time.localtime(timestamp)
      res = time.strftime(format,time_tuple)
      else:
      res = time.strftime(format)
      return res
       
      print(timestamp_to_fomat())
      print(timestamp_to_fomat(19732649413))
       
      # 時間轉換成時間戳
      #1.把格式化的時間轉換成時間元組
      #2.把元組轉換成時間戳
      res = time.strptime('20180421','%Y%m%d')
      print(res)
      print(time.mktime(res))
       
      格式化時間轉換時間戳的函數:
      # 時間轉換成時間戳
      #1.把格式化的時間轉換成時間元組
      #2.把元組轉換成時間戳
      res = time.strptime('20180421','%Y%m%d')
      print(res)
      print(time.mktime(res))
       
      def strToTimestamp(str = None,format = '%Y%m%d'):
      if str:
      tp = time.strptime(str,format)
      res = time.mktime(tp)
      else:
      res = time.time()
      return int(res)
       
      print(strToTimestamp())
      print(strToTimestamp('2018-02-15','%Y-%m-%d'))
       
      datetime 模塊
      import datetime
      print(datetime.datetime.today()) #獲取當前時間,精確到秒
      print(datetime.date.today()) #精確到天
      day = datetime.date.today() + datetime.timedelta(days=5)
      print(day)
       
      min = datetime.datetime.today() + datetime.timedelta(days=1,minutes=5,seconds=5,weeks=1)
      print(min)
       
      print(min.strftime('%Y-%m-%d'))
       
      加密模塊
      import hashlib
      m = hashlib.md5()
      # print(m.__doc__) #查看有哪些方法
      print(m.hexdigest()) #對空加密
       
      passwd = 'aaa123'
      print(passwd.encode()) #把字符串轉換成bytes類型,加密不能對字符串進行加密,要轉換成bytes類型
      m.update(passwd.encode())
      print(m.hexdigest())
      #md5加密是不可逆的
       
      網上md5解密是采用的撞庫來查詢的。
      def my_md5(srt):
      import hashlib
      new_str = str.encode() #把字符串轉換層buytes類型
      m = hashlib.md5() #實例化md5對象
      m.update(new_str) #加密
      return m.hexdigest() #獲取結果返回
       
       
       
      posted @ 2018-05-18 20:22  JosephPeng  閱讀(201)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 久久国产精品成人影院| 色综合色综合久久综合频道| 久久经精品久久精品免费观看| 日本丰满白嫩大屁股ass| 潮喷无码正在播放| 98日韩精品人妻一二区| 亚洲熟女综合色一区二区三区| 久久婷婷五月综合色一区二区 | 成在线人午夜剧场免费无码| 尉氏县| 国产精品日韩专区第一页| 各种少妇wbb撒尿| 国产精品看高国产精品不卡| 2019国产精品青青草原| 日韩av毛片福利国产福利| 久久被窝亚洲精品爽爽爽| 天堂V亚洲国产V第一次| 男女xx00xx的视频免费观看| 亚洲日韩久热中文字幕| 狠狠色噜噜狠狠狠狠色综合久av| 亚洲国产av区一区二| 黑人大荫道bbwbbb高潮潮喷| 国产精品久久久久久久专区| 性动态图无遮挡试看30秒| 日本美女性亚洲精品黄色| 亚洲aⅴ无码专区在线观看春色| 日韩av日韩av在线| 国精品午夜福利不卡视频| 日本久久久免费高清| 中国女人熟毛茸茸A毛片| 夜夜春久久天堂亚洲精品| 又大又硬又爽免费视频| 无码人妻一区二区三区线| 九九热在线视频观看精品| 一本久久a久久精品综合| 日韩av熟女人妻一区二| 亚洲人妻一区二区精品| 国产高潮国产高潮久久久| 亚洲性人人天天夜夜摸18禁止| 亚洲男女一区二区三区| 高清免费毛片|