利用python进行文件读取
报错消息:
IOError: [Errno 2] No such file or directory
原因:与文件路径有关
利用代码查看当前工作路径
import os
print os.getcwd() #打印出当前工作路径
将要读取的文件放在这个路径中,或者修改工作路径:
os.chdir('the dir which include the file a.txt') #修改当前工作目录
利用python进行文件读取
报错消息:
IOError: [Errno 2] No such file or directory
原因:与文件路径有关
利用代码查看当前工作路径
import os
print os.getcwd() #打印出当前工作路径
将要读取的文件放在这个路径中,或者修改工作路径:
os.chdir('the dir which include the file a.txt') #修改当前工作目录