摘要:
""" 异常处理 包括异常捕获、抛异常和assert date:2023-01-29 """ # 捕获异常 try: 1 / 0 except ZeroDivisionError as e: print(e) # division by zero try: 1 / 1 520 + "hi" exce 阅读全文
摘要:
""" 文件相关操作(pathlib) date:2023-01-29 """ from pathlib import Path # 获取当前工作目录 print(Path.cwd()) # D:\workspace\py\python_demo\root\demo\study_demo\file_ 阅读全文
摘要:
# 文件读取、写入和异常处理操作举例 # 带参数encoding='utf-8'可解决UnicodeDecodeError编码问题 ###### 基础方法 ###### # 新建文件并覆盖写入 file_path = "D:\\test_data\\test.txt" f = open(file_p 阅读全文