问答 / 0 / 4 / 创建于 5年前
contents=file_object.read() print(contents)
请修改代码, 测试一下
import os ... # 确认目录所在为你的 python_work print(os.getcwd()) # 要检查的档案路径 filepath = 'pi_digits.txt' # 检查档案是否存在 if os.path.isfile(filepath): print("档案存在。") else: print("档案不存在。") with open(filepath) as file_object: contents=file_object.read() print(contents) ...
你好,还是显示文档不存在
你没搞对重点, 截屏中没重要内容, 而且没有你的相关代码
c:\Users\as\Destop\python_work> dir <== 少了這个 .. aa.py pi_digits.txt .. c:\Users\as\Destop\python_work> python aa.py <=== 还有這个 c:\Users\as\Destop\python_work 档案不存在. Traceback (most recent call last): File "aa.py", line 16, in <module> with opne(filepath) as file_object: FileNotFoundError: [Error 2] No such file or directory: 'pi_digits.txt' 请按任意键继续... c:\Users\as\Destop\python_work> type aa.py ...
相对路径不正确,可以参考在操作系统下的的相对路径表示法
我要举报该,理由是:
请修改代码, 测试一下
你没搞对重点, 截屏中没重要内容, 而且没有你的相关代码
相对路径不正确,可以参考在操作系统下的的相对路径表示法