對於老師課程上完就應該有的實力,太高估自己
還要在這條路上的話,就算是簡單的題目也好
能夠每天接觸才是重要的
下午爬蟲課只知道200狀態碼代表向伺服器請求成功
用get請求時網址會揭露key value明碼,用POST請求內容較不容易被發現
- requests 庫的基本使用方法和優勢。
- HTTP 請求的不同方法 (GET, POST) 以及如何使用 requests 發送這些請求。
- 請求標頭 (Headers) 的作用以及如何在 requests 中設定。
- URL 查詢參數 (Query Parameters) 的傳遞方式。
- 請求體 (Request Body) 的概念以及如何在 POST 請求中傳遞不同格式的資料。
- 如何處理伺服器的回應,包括狀態碼、內容、編碼、標頭和 JSON 資料。
- Cookies 的處理。
- HTTP 重定向的機制以及如何在 requests 中控制重定向。
- 設定請求超時以提高程式的健壯性。
- Session 物件的使用場景。
- 基本的錯誤處理。
5/20要完成python大數據視覺化報告
30個台灣開放數據平台資源_分析師必收藏的數據資源寶典
上午講解ITS後半的題庫
Python中的Assert语句简明教程
assert用於程式的除錯和測試階段。它的作用是檢查一個條件是否為真。如果條件為真,程式會繼續正常執行;
如果條件為假,Python 會觸發一個 AssertionError 異常,並且可以選擇性地附帶一個錯誤訊息。
你可以把它想像成程式中的一個自我檢查點,用來確保程式在某個時間點的狀態符合你的預期。
def cube(num):
"""傳回數字 num 的立方值"""
return num*num*num
print(cube.__doc__)
使用了點號運算符 (.) 來存取 cube 函數的屬性。
cube.__doc__ 會返回 cube 函數的文檔字串,
也就是 "傳回數字 num 的立方值"
然後,print() 函數會將這個字串印出來。
字符串格式化(String Formatting)主要有 三種常見寫法,分別是:
1.舊式格式化(% 運算子)Python 2 時代的主流方法,現在仍可用,但不推薦在新代碼中使用。
name = "Alice"
age = 25
print("Hello, %s! You are %d years old." % (name, age))
# 輸出: Hello, Alice! You are 25 years old.
%s 表示字符串,%d 表示整數,%f 表示浮點數。
2.str.format() 方法Python 2.6+ 和 Python 3 推薦的格式化方法,更靈活。
name = "Bob"
age = 30
print("Hello, {}! You are {} years old.".format(name, age))
# 輸出: Hello, Bob! You are 30 years old.
可指定順序或名稱:
print("Hello, {1}! You are {0} years old.".format(age, name))
print("Hello, {name}! You are {age} years old.".format(name="Charlie", age=35))
3.f-strings(格式化字符串字面值,Python 3.6+)最新、最簡潔的寫法,直接在字符串中嵌入變數或表達式。
name = "David"
age = 40
print(f"Hello, {name}! You are {age} years old.")
# 輸出: Hello, David! You are 40 years old.
支援表達式計算:
a, b = 5, 10
print(f"The sum of {a} and {b} is {a + b}.")
# 輸出: The sum of 5 and 10 is 15.
進階格式化技巧
所有方法都支援格式化數字、對齊等:
# 浮點數保留 2 位小數
pi = 3.1415926
print("pi = %.2f" % pi) # 舊式
print("pi = {:.2f}".format(pi)) # str.format
print(f"pi = {pi:.2f}") # f-string
# 對齊文字(寬度 10,靠右)
text = "Python"
print("|%10s|" % text) # 舊式
print("|{:>10}|".format(text)) # str.format
print(f"|{text:>10}|") # f-string
一次看懂遞迴 (Recursion) 的思維模式(一)
遞迴列出目錄所有檔案
import os
def list_files(startpath):
for root, dirs, files in os.walk(startpath):
level = root.replace(startpath, '').count(os.sep)
indent = ' ' * 4 * level
print(f"{indent}{os.path.basename(root)}/")
subindent = ' ' * 4 * (level + 1)
for f in files:
print(f"{subindent}{f}")
list_files('.')
1. 檔案與目錄操作
2. 程序與系統管理
3. 檔案描述符與權限
4. 其他實用功能
路徑管理
import sys
import os
# 確保腳本所在目錄在模組搜索路徑中
script_dir = os.path.dirname(os.path.abspath(__file__))
if script_dir not in sys.path:
sys.path.insert(0, script_dir)
sys 模組是 Python 標準庫中與 Python 解釋器交互的核心模組,提供了許多與系統相關的功能和變數。以下是 sys 模組的主要功能和應用:
1. 系統參數與路徑管理
2. 標準輸入/輸出流
3. 系統相關資訊
4. 遞迴與系統限制
5. 程序控制與退出
6. 模組與內建函數
7. 進階功能
