IOError: [Errno 2] No such file or directory
程序员文章站
2022-07-15 17:00:23
...
利用python进行文件读取
报错消息:
IOError: [Errno 2] No such file or directory
原因:与文件路径有关
利用代码查看当前工作路径
import os
print os.getcwd() #打印出当前工作路径
将要读取的文件放在这个路径中,或者修改工作路径:
os.chdir('the dir which include the file a.txt') #修改当前工作目录
推荐阅读
-
Django报错:python: can‘t open file ‘manage.py‘: [Errno 2] No such file or directory
-
python: can‘t open file ‘sqlmap.py‘: [Errno 2] No such file or directory
-
- bash: /usr/bin/ls: /lib64/ld-linux-x86-64.so.2: bad ELF interpreter: No such file or directory
-
Python open: FileNotFoundError: [Errno 2] No such file or directory
-
IOError: [Errno 2] No such file or directory
-
Yum:[Errno 5] [Errno 2] No such file or directory
-
Yum:[Errno 5] [Errno 2] No such file or directory
-
FileNotFoundError: [Errno 2] No such file or directory:
-
Yum:[Errno 5] [Errno 2] No such file or directory
-
libiconv.so.2 cannot open shared object file: No such file or directory