自己建立的csv檔案:

除了奇異的那一列
每一列都有四筆資料
要如何取出第四直欄?
如果直接取的話
因為奇異列的長度太短
會出現
IndexError: list index out of range
用try~except~語法
pass IndexError
#沒縮排會出現 ValueError: I/O operation on closed file.
#奇異列為一個空白跟一個空元素

推薦hahow線上學習python: https://igrape.net/30afN

例外觸發程序:

捕捉例外狀況:

推薦hahow線上學習python: https://igrape.net/30afN



]*>.*?底下插入一個圖檔.*?</w:p>’, flags = re.DOTALL) ; new_xml, n = pattern.subn(”, xml, count=1)' title='Python正則替換:全面掌握 re.sub 與 re.subn 的差異與實戰 #substitute(替換); . 預設匹配「除\n以外的任意單一字元」; pattern = re.compile(r'<w:p[^>]*>.*?底下插入一個圖檔.*?</w:p>’, flags = re.DOTALL) ; new_xml, n = pattern.subn(”, xml, count=1)' loading='lazy' width=350 height=233 />





近期留言