环境: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. android系统自带图标

      android:src="@android:drawable/ic_media_rew"    

  2. 图片转成base64的字符串, 如何让图片在html中显示

    图片在服务端已编码成base64的字符串放在xml里面,客户端接受xml,取得base64的字符串后,请问如何让图片在html中显示? <img src="data:image/png ...

  3. Linux系统下JDK安装配置(转载)

    转载出处:http://www.cnblogs.com/xuliangxing/p/7066913.html 本文主要介绍的是如何是Linux环境下安装JDK的,因为Linux环境下,很多时候也离不开 ...

  4. PAT 1040

    字符串APPAPT中包含了两个单词"PAT",其中第一个PAT是第2位(P),第4位(A),第6位(T):第二个PAT是第3位(P),第4位(A),第6位(T). 现给定字符串,问 ...

  5. HDU_3486_Interviewe

    Interviewe Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  6. 一次tns连接错误的解决过程

    --同事hadoop连接oracle导入数据,界面报错,后台alert日志报错tns相关错误: **************************************************** ...

  7. Kafka Producer接口

    参考, https://cwiki.apache.org/confluence/display/KAFKA/0.8.0+Producer+Example http://kafka.apache.org ...

  8. js-jquery-从SweetAlert到SweetAlert2

    原文地址:https://github.com/limonte/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2 1. IE supp ...

  9. CSLA.Net学习(3)INotifyPropertyChanged和IDataErrorInfo

    今天晕晕糊糊的看CSLA.net,希望能找到验证数据正确性的方法,还是摸索出了INotifyPropertyChanged, IDataErrorInfo接口的使用方法,通过INotifyProper ...

  10. python高级之scrapy框架

    目录: 爬虫性能原理 scrapy框架解析 一.爬虫性能原理 在编写爬虫时,性能的消耗主要在IO请求中,当单进程单线程模式下请求URL时必然会引起等待,从而使得请求整体变慢. 1.同步执行 impor ...