学习python的文件处理,刚开始打开文件,代码如下

f = open('test_file.txt', 'r', encoding='UTF-8')
RES = f.readlines()
print('读取的内容%s' % RES)
f.close() 这里运行报错FileNotFoundError: [Errno 2] No such file or directory: 'test_file.txt'
意思是没有这个文件? 后来发现是因为多了后缀
修改代码:把文件名的后缀去掉了
f = open('test_file', 'r', encoding='UTF-8')
RES = f.readlines()
print('读取的内容%s' % RES)
f.close() 运行成功:结果如下
读取的内容['1.zyh\n', '2.1995\n', '3.gggg'] 注意:要读取的文件与py当前编辑的文件在同一个文件夹下,就不用加路径,不是同一个文件夹就要在文件名前面加路径
f = open('D:/zyh_test/test_file', 'r', encoding='UTF-8')
RES = f.readlines()
print('读取的内容%s' % RES)
f.close()

Python中的用open打开文件错误,FileNotFoundError: [Errno 2] No such file or directory:的更多相关文章

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

    环境:Windows8.1, Python3.6  pycharm community 2017   c盘下有一个配置文件:setup   with open('c:\\setup','r') as ...

  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. 对于python中“FileNotFoundError: [Errno 2] No such file or directory”的解决办法

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

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

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

  6. VSCode python 遇到的问题:vscode can't open file '<unprintable file name>': [Errno 2] No such file or directory

    代码很简单,就两行: import pandas as pd import netCDF4 as nc dataset = nc.Dataset('20150101.nc') 环境:在VSCode中左 ...

  7. python中reload(module)的用法,以及错误提示

    1.Python2中可以和Python3中关于reload()用法的区别. Python2 中可以直接使用reload(module)重载模块.   Pyhton3中需要使用如下两种方式: 方式(1) ...

  8. python中configparser模块读取ini文件

    python中configparser模块读取ini文件 ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(se ...

  9. Python 中当前位置以及目录文件遍历操作

    Python 中当前位置以及目录文件遍历操作 当前位置 print(os.path.dirname(__file__)) 其中 dirname 会选择目录(文件夹),"__file__&qu ...

随机推荐

  1. 对接口运用扩展方法 Applying Extension Methods to an Interface 精通ASP-NET-MVC-5-弗瑞曼 Listing 4-15

  2. Java的String类常用方法

    一.构造函数 String(byte[ ] bytes):通过byte数组构造字符串对象. String(char[ ] value):通过char数组构造字符串对象. String(Sting or ...

  3. HDU 3839 Ancient Messages(DFS)

    In order to understand early civilizations, archaeologists often study texts written in ancient lang ...

  4. Git基础常用功能

    一.安装 具体查看 安装Git 二.使用 基础知识 工作区(Workspace):就是你在电脑里能看到的项目目录. 暂存区(Index / Stage):临时存放更改的地方,使用命令"git ...

  5. Docker底层架构之命名空间

    前言 命名空间是 Linux 内核一个强大的特性.每个容器都有自己单独的命名空间,运行在其中的 应用都像是在独立的操作系统中运行一样.命名空间保证了容器之间彼此互不影响.相应的命名空间功能如下: pi ...

  6. 使用nutz框架,找不到入口函数,访问Url报404

    案例 今天在跟着nutz框架教程去配置demo时,发现访问URL找不到入口函数,出现了Search mapping for path=/user/count : NOT Action match 异常 ...

  7. 3、MySQL 索引失效的场景

    索引失效的场景: 1.没有 where 条件 直接看 SQL 语句   2.where 条件中所在的列没有建立索引 show index from t;   3.从表中取得数据超过某个阈值.通常认为是 ...

  8. MySQL物理物理备份与还原工具xtraBackup

    (一)xtraBackup简介 xtraBackup是Percona公司开发的一款MySQL数据库备份软件,在备份模式中属于物理备份.其显著特点是开源.免费.备份执行过程中不会阻塞事物.备份可压缩.支 ...

  9. java加解密算法--DES

    ECB import sun.misc.BASE64Decoder; import javax.crypto.*; import javax.crypto.spec.DESKeySpec; impor ...

  10. QQ截图工具截取

    邮箱截图插件 TXGYMailCamera.dll(X86) Export: CameraWindow CameraSubArea CameraWindowLikeSpy 调用参数: rundll32 ...