1. 程式人生 > >Python Try Except

Python Try Except

Python Try: Except

Except 型別一:
        try:
            file_size = os.path.getsize('maoyan.csv');
        except  OSError as err:
            name = ['評論日期', '評論者暱稱', '性別', '所在城市', '貓眼等級', '評分', '評論內容']
            # 建立DataFrame物件
            file_test = pd.DataFrame(columns=name, data=list_info)
            # 資料寫入
            file_test.to_csv(
'maoyan.csv', encoding='utf_8_sig', index=False)