def file_read(path:str):
#文本文件读取异常处理
try:
with open(path,mode="r") as fd:
content = fd.readline()
print(content)
return {'status':True,'data':content}
except Exception as e:
#获取错误信息
error_content = "读写文本文件异常,具体原因:" + str(e)
return {'status':False,'Error':error_content}
if __name__ == '__main__':
#r代表不转义,如果不加r那么""中就需要加双反斜杠
path = r"D:\Python\Project\listen3\file\工单-测试.csv"
content = file_read(path)
print(content['status'])