python
Road Map
最近更新日期20210108
Python3 講義目錄
老師完整講義
VSCODE(VisualStudio Code) 快速鍵
VSCode 常用快速鍵
基本語法
註解,print與格式化字串
基本語法二
字串處理
Python 資料型別
序對(tuple) 、 串列[list] 、 {字典:dict} 與 集合{set}
資料型別
老師講義
流程控制
if、for、while、continue、break、pass 用法
除錯與與異常處理
logging用法(分別寫出log文字檔與console訊息)
pip用法與套件簡易說明
import 用法,各套件簡易說明。
SQLite
老師講義
資料庫處理
資料庫連線方法,插入一筆資料,更新資料,插入大量資料,資料庫時間之處理
寫入資料庫語法
寫入mongodb程式碼,寫入mysql程式碼
網頁資料抓取與分析
用ParseResult物件,取得網址資料;用Beautifulsoup進行複雜網頁分析
網路爬蟲
使用到的套件,安裝方法
物件導向程式設計
老師講義
內建指令快速架設網站方法
Python 3快速建立網頁伺服器 Web server
快速建立簡單網頁伺服器 http websever
Python3 語法:切換到要開放的資料夾目錄下輸入下列指令
python -m http.server 8080
自己寫WebServer 程式碼方法
# python3-httpserver.py
#!/usr/bin/env python3
-*- coding: utf-8 -*-
import sys
import http.server
from http.server import SimpleHTTPRequestHandler
HandlerClass = SimpleHTTPRequestHandler
ServerClass = http.server.HTTPServer
Protocol = "HTTP/1.0"
if sys.argv[1:]:
port = int(sys.argv[1])
else:
port = 8000
server_address = ('127.0.0.1', port)
HandlerClass.protocol_version = Protocol
httpd = ServerClass(server_address, HandlerClass)
sa = httpd.socket.getsockname()
print("Serving HTTP on", sa[0], "port", sa[1], "...")
httpd.serve_forever()
Python2 語法:
python -m SimpleHTTPServer
自己寫WebServer 程式碼方法
# python2-httpserver.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
HandlerClass = SimpleHTTPRequestHandler
ServerClass = BaseHTTPServer.HTTPServer
Protocol = "HTTP/1.0"
if sys.argv[1:]:
port = int(sys.argv[1])
else:
port = 8000
server_address = ('127.0.0.1', port)
HandlerClass.protocol_version = Protocol
httpd = ServerClass(server_address, HandlerClass)
sa = httpd.socket.getsockname()
print("Serving HTTP on " + str(sa[0]) + " port " + str(sa[1]) + "...")
httpd.serve_forever()
Python 範例:Python 伺服器程式碼 (server.py)
這種架設方法:算是低階的嵌入式網站伺服器, 沒有資安與效能的考量, 只是提供開發測試用的。
可用於個人用於簡單網頁顯示。
若要在商業與生產環境下使用, 建議使用生產等級的網站伺服器: Nginx, Apache,…等等。
相關參考資料
從範例學程式初階 – Python(1080801-02)
python-cheatsheet
Python範例 含有PEP8 PYTHON 編碼規範手冊介紹(程式撰寫風格)
S20200730 By YTC
M20200807,20200814,20200919,20200929,20201005,20201204
M20210102,20210108