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

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

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

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

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

换成

 filename = 'c:\\setup.log' 

所有问题解决

PS:所有Windows下的文件路径,一律用双反斜杠

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

  1. Python中的用open打开文件错误,FileNotFoundError: [Errno 2] No such file or directory:

    学习python的文件处理,刚开始打开文件,代码如下 f = open('test_file.txt', 'r', encoding='UTF-8')RES = f.readlines()print( ...

  2. 关于python中的 “ FileNotFoundError: [Errno 2] No such file or directory: '……'问题 ”

    今天在学python时,在模仿一个为图片加上图标并移动到指定文件夹的程序时遇到“FileNotFoundError: [Errno 2] No such file or directory: '152 ...

  3. 关于JPype报FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/jvm'错误的解决

    部署到线上的项目正常运行一年,今天早上突然报FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/jvm'错误. JPyp ...

  4. FileNotFoundError: [Errno 2] No such file or directory: 'image/1.jpg'问题解决

    FileNotFoundError: [Errno 2] No such file or directory: 'image/1.jpg'问题 最近在学习爬虫,想爬一些图片并保存到本地,但是在下载图片 ...

  5. 对于python中“FileNotFoundError: [Errno 2] No such file or directory”的解决办法

    在我们使用vscode运行Python代码时遇到的情况 一.出现原因:这里是由于Vscode中,python里的路径是相对与工作目录来进行定位的.所以在多级目录情况下,若不设置绝对路径,往往找不到相应 ...

  6. FileNotFoundError: [Errno 2] No such file or directory的解决方法

    1.获取当前文件所在路径 basedir = os.path.dirname(__file__) print("basedir:" + basedir) 2.将路径进行拼接 upl ...

  7. python3 使用selenium +webdriver打开chrome失败,报错:FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'

    提示chrome driver没有放置在正确的路径下 解决方法: 1.chromedriver与chrome各版本及下载地址 驱动的下载地址如下: http://chromedriver.storag ...

  8. Python文件操作之把臂入林

    文件操作1.打开文件open(file, mode='r', buffering=None, encoding=None, errors=None, newline=None, closefd=Tru ...

  9. Python 文件操作(1)

    今天大佬给了个A文件给我,里面存放了机密数据. 什么机密数据??? 有帅哥的联系方式吗? 赶紧打开来看一下 1.open() 函数基本版 Python大佬有个内置开文件的函数open(), 专门开文件 ...

随机推荐

  1. Video如何不自动全屏播放?

    知乎:微信内置浏览器 如何小窗不全屏播放视频? 目前在微信中只能全屏播放,只有加入腾讯白名单的视频才能小屏播放. 知乎上讨论的解决方案尚未测试,太麻烦了.

  2. 【BZOJ2668】[cqoi2012]交换棋子 费用流

    [BZOJ2668][cqoi2012]交换棋子 Description 有一个n行m列的黑白棋盘,你每次可以交换两个相邻格子(相邻是指有公共边或公共顶点)中的棋子,最终达到目标状态.要求第i行第j列 ...

  3. angularJS的路由!

    angularJS 路由:(分发需求) angularJS 中路由是单独提供的功能模块,ngRoute  也是一个单独发行的文件 可以通过 npm 去安装这个包:angular-route <s ...

  4. spfile与pfile

    SYS@ora11g>show parameter spfile NAME TYPE------------------------------------ ------------------ ...

  5. 树链剖分+线段树+离线(广州网选赛第八题hdu5029)

    http://acm.hdu.edu.cn/showproblem.php?pid=5029 Relief grain Time Limit: 10000/5000 MS (Java/Others)  ...

  6. Java定时器和Quartz使用

    一.Java普通自定义定时器 /** * 自定义一个定时器 * @author lw */ public class MyTimer extends Thread{ private Long time ...

  7. postgresql----UNION&&INTERSECT&&EXCEPT

    多个SELECT语句可以使用UNION,INTERSECT和EXCEPT进行集合处理,其中UNION用于求并集,INTERSECT用于求交集,EXCEPT用于求差集.用法如下 query1 UNION ...

  8. Python爬虫基础(四)Requests库的使用

    requests文档 首先需要安装:pip install requests get请求 最基本的get: # -*- coding: utf-8 -*-import requests respons ...

  9. talib 中文文档(十五):Math Operator Functions 数学方法

    Math Operator Functions 数学运算符函数 ADD - Vector Arithmetic Add 函数名:ADD 名称:向量加法运算 real = ADD(high, low) ...

  10. HDU Today---hdu2112(最短路-_-坑在是无向图)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2112 spfa或者迪杰斯特拉都可以 注意公交车是有来回的--- #include <iostre ...