IOError: [Errno 2] No such file or directory

利用python进行文件读取
报错消息:

IOError: [Errno 2] No such file or directory

原因:与文件路径有关

利用代码查看当前工作路径

import os

print os.getcwd() #打印出当前工作路径 

将要读取的文件放在这个路径中,或者修改工作路径:

os.chdir('the dir which include the file a.txt') #修改当前工作目录
发布了22 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/helloworld987456/article/details/94445962