Python Try Except

时间:2023-03-09 20:56:55
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)

https://docs.python.org/3/tutorial/errors.html