1. 程式人生 > >python基礎-模塊學習

python基礎-模塊學習

語言 () 是否 導入模塊 format random 生成 自定義模塊 light

1.定義:
模塊:用來從邏輯上組織python代碼(變量、函數、類、邏輯:實現一個功能),本質就是.py結尾的python文件。
包:用來從邏輯上組織模塊,本質是一個目錄(必須帶有一個叫__init__.py文件)

2.導入方法
導入模塊:
import module1,module2
from module1 import *
from module1 import logger(模塊) as logger2(別名)
導入包:import

3.import本質(路徑搜索和搜索路徑)
導入模塊:把python文件解釋一遍
導入包:執行該包下的init.py文件


4.導入優化
from module_test import test

5.模塊分類
a.標準庫
b.開源模塊
c.自定義模塊
標準庫:
1.time與datetime 時間戳,格式化時間輸出,元組
time:
timezone(UTC to 秒)、altzone(UTC and DST to 秒)、daylight(是否使用DST)
functions:
time() 時間戳time.time()
clock()
sleep() 延時
gmtime() seconds to () UTC
localtime() seconds to () local

asctime() tuple to string %a(星期) %b(月) %d(日) %H %M %S %Y(年)
ctime() 時間戳seconds轉化為上面的格式
mktime() local to seconds
strftime() tuple to string strftime(format,tuple)
strptime() string to tuple strptime(string,format)
tzset()
2.random模塊
3.OS模塊
4.sys模塊
5.shutil模塊 高級的文件、文件夾、壓縮包處理模塊

6.json、pickle模塊
7.shelve模塊 pickle
8.xml處理模塊 實現不同語言或程序之間進行數據交換的協議
9.ConfigParser模塊 用於生成和修改常見配置文檔
10.hashlib模塊 用於加密相關的操作

python基礎-模塊學習