python文件操作的坑( FileNotFoundError: [Errno 2] No such file or directory...)

时间:2017-06-24 16:47:30   收藏:0   阅读:4292

环境:Windows8.1, Python3.6  pycharm community 2017

 
c盘下有一个配置文件:setup
 
1 with open(c:\\setup,r) as f:
2         f.read()

提示一直很诡异:FileNotFoundError: [Errno 2] No such file or directory: ‘c:\\setup‘

 

网上有大量关于Python编码错误导致无法打开文件的解决方法,utf8 gbk2312,尝试过一遍全部无效

最后原因很乌龙:setup后缀是*.log

换成

1 filename = c:\\setup.log 

所有问题解决

原文:http://www.cnblogs.com/fanyuchen/p/7073629.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!