新修保險法:保單主動通報 by 儲蓄保險王 · 2015-01-19 相關文章Python × lxml.etree:從 Word OOXML 讀、查、改、寫的實戰筆記; from lxml import etree ; parser = etree.XMLParser() ; root = etree.fromstring(xml.encode("utf-8"), parser=parser) #(根節點); print(etree.tostring(root, encoding="unicode", pretty_print=True)) #encoding="unicode"輸出str ; "utf-8"輸出bytes,漂亮顯示告別雜亂 XML!用 Python lxml 實現與 VS Code (Shift+Alt+F) 同級的「完美縮排」root = etree.fromstring(xml_bytes) ; clean_xml_str = etree.tostring(root, pretty_print=True, encoding='unicode', xml_declaration=False)Python-docx 進階手術室:從底層 XML 到超連結混合技; from docx.opc.constants import RELATIONSHIP_TYPE as RT ; part = doc.part ; r_id = part.relate_to(url, RT.HYPERLINK, is_external=True)Python 讀取 DOCX 圖片關聯:qn+find/findall 與 XPath 的實戰對照 from lxml import etree ; from docx.oxml.ns import qn; lxml.etree._Element.findall( f".//{ qn('a:blip') }" ) ; .get( qn("r:embed") ) #獲取 屬性名 'r:embed' 的 屬性值(如: 'rId4') ; lxml.etree._Element.xpath( "//a:blip/@r:embed", namespaces = NS) #/@r:embed = 獲取 屬性名 'r:embed' 的 屬性值(如: 'rId4'),使用.findall() 要先.findall()獲取List[_Element],再迴圈_Element.get()獲取屬性值, .xpath() 第一個參數path 使用"//a:blip/@r:embed" ,可直接獲取屬性值(List[str]如: ['rId4', 'rId5']) ; 如何對docx真實移除圖片瘦身?Python 入門教學:用 Path.stat() 與 os.stat() 讀懂檔案資訊; from pathlib import Path ; type(p).__name__ #'WindowsPath'; p.stat().st_size == os.stat(p).st_size == os.path.getsize(p)python-docx 進階手術室:從高階 API 到底層 XML (w:p, w:r, w:t) 完全解析; from docx.oxml import OxmlElement ; from docx.oxml.ns import qnPython tempfile 模組完全指南:安全管理臨時檔案的最佳實踐; import tempfile ; tempfile.gettempdir() ; tempfile.template ; os.access(temp_dir, os.W_OK) ; with tempfile.NamedTemporaryFile() as tmp: tmp_path = tmp.name #有檔名的臨時檔案 ; with tempfile.TemporaryDirectory() as tmpdir #臨時資料夾 ; with tempfile.TemporaryFile() as tmp #無檔名的臨時檔案Python Regex 實戰:精準抓取 XML 屬性值 (findall vs finditer 與 Group 的奧義)Python hashlib 快速入門:為資料建立唯一指紋import hashlib; data = "文字".encode('utf-8'); hash_obj = hashlib.sha256(data); result = hash_obj.hexdigest() #digest:「取得雜湊摘要」或「取得摘要值」
近期留言