0 攝影或3C 2025-12-23 以 python-docx 的 CT_P 為例看 MRO (Method Resolution Order, 方法解析順序) MRO 全名是 Method Resolution Order(方法...
0 攝影或3C 2025-12-22 Python 進階:解剖 Word 底層 – 手動封裝 CT_P 與 CT_Tbl 全攻略; from docx.text.paragraph import Paragraph ; from docx.table import Table; para = Paragraph(child, doc) ; table = Table(child, doc) 在使用 python-docx 時,我們通常習慣使用 doc.par...
0 攝影或3C 2025-12-21 Python-docx 進階心法:穿梭於「表層 Paragraph」與「底層 CT_P」之間 在使用 python-docx 自動化處理 Word 文件時,我們通...
0 攝影或3C 2025-12-20 Python 高階函數三劍客: map、filter、reduce #以函數作為參數,或回傳函數的函數; list(filter(None, data)) ; reduce( lambda acc, x: acc + x, map(lambda x: x * 2, filter(lambda x: x % 2 == 0, numbers))) 在 Python 中,map、filter、reduce 是三個非常...
0 攝影或3C 2025-12-16 Python 實戰:拒絕麵條式代碼!用 Lambda + Next 重構成績評級系統; grade = next(result for condition, result in rules if condition(score)) 在 Python 開發中,處理「區間判斷」是家常便飯。最經典的例子就...
0 攝影或3C 2025-12-16 Python 三元運算子 (Ternary Operator) 完全指南; status = “成年” if age >= 18 else “未成年” ; 值_如果為真 if 條件判斷 else 值_如果為假 #取這個值 (如果條件成立),否則 (取那個值) 在寫程式時,我們經常遇到需要根據條件將變數設為不同值的情況。傳統的 ...
0 攝影或3C 2025-12-08 Python XML 的生死輪迴:深入理解 lxml.etree.fromstring(xml_bytes) #Bytes → Element Object 與 lxml.etree.tostring(Element, encoding= “utf-8”) #Element Object → Bytes ; lxml.etree._Element; 處理 XML 時,盡量全程保持 Bytes (二進位) 狀態。 在處理 DOCX (Zip) 內的 XML 時,我們無法直接修改壓縮...
0 攝影或3C 2025-12-07 Python Zipfile 實戰:Write vs Writestr —— 硬碟搬運工與記憶體魔術師; XML 處理的世界裡,writestr 才是真正的主角; zf.writestr(zinfo_or_arcname, data) #zinfo_or_arcname: ZipInfo | str ; data: bytes | str 在處理 docx(本質上是 Zip)或一般壓縮檔時,我們最常糾結的就...
近期留言