- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用以下代码打开一个 txt 文件进行阅读:-
type_comments = [] #Declare an empty list
with open ('society6comments.txt', 'rt') as in_file: #Open file for reading of text data.
for line in in_file: #For each line of text store in a string variable named "line", and
type_comments.append(line.rstrip('\n')) #add that line to our list of lines.
错误:-
Error - Traceback (most recent call last):
File "c:/Users/sultan/python/society6/society6_promotion.py", line 6, in <module>
with open ('society6comments.txt', 'rt') as in_file:
FileNotFoundError: [Errno 2] No such file or directory: 'society6comments.txt'
我的脚本在同一目录中已经有一个名为“society6comments.txt”的文件,那么为什么它显示错误?
最佳答案
文本文件与程序位于同一目录中这一事实并不会使该目录成为当前工作目录。将文件的完整路径放入 open()
调用中。
关于python - 使用python打开txt文件时出现FileNotFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52407669/
from os import path from pydub import AudioSegment input_file = "audio.mp3" output_file = "result.wa
尝试运行 mask_rcnn 的示例程序颜色飞溅并收到此错误: 我正在环境中的 anaconda 上运行 mrcnn 模型masknet,并安装了以下软件包。我已按照 https://github
我正在尝试使用 PySerial 来接受来自 RFID 阅读器的输入。根据 here: 的答案,我尝试使用 WinObj 并发现一些奇怪的东西:COM3 文件夹中没有 GLOBAL??? 端口指向“更
我有一个奇怪的问题。我既不能重命名特定文件,也不能删除它们。我收到 FileNotFoundError。 以前也有人问过类似的问题。此问题的解决方案是使用完整路径,而不仅仅是文件名。 我的脚本在仅使用
我有一个文本文件“Flickr_8k.testImages.txt”,其中包含由换行符分隔的 1000 个文件的文件名。这些文件位于目录“Flickr8k_Dataset”内,其中包含 8000 多个
我正在尝试制作一个简单的程序,将具有用户指定扩展名的所有文件复制到另一个文件夹中。代码如下,错误如下: #! python3 # Copies all files from folder with u
我的 Python 应用程序包含一个名为 Tests 的子文件夹,我用它来运行单元测试。我的所有文件都位于父文件夹中,我将其称为 App。例如,Tests 文件夹包含一个 test.py 文件。 Ap
我有一个函数,它获取包含时间的源文件(csv 文件),读取它,然后按顺序对行进行排序并将它们写入目标文件中。但是,如果源 csv 文件不存在,我需要引发 FileNotFoundError。我之前曾引
我收到 FileNotFoundError当用户尝试注册我的网站并上传照片时出现错误消息。错误消息如下: [Errno 2] No such file or directory: '/tmp/.upl
我正在尝试关注 this blog关于如何从 Python 执行 R 脚本。我使用 Rscript 从命令行运行 R 脚本。 这是我的 Python 代码: import subprocess imp
使用 Windows 7、Python 3.5.1: import subprocess subprocess.check_output(['echo', 'hello']) 引发错误: Traceb
这个问题在这里已经有了答案: open() gives FileNotFoundError/IOError: Errno 2 No such file or directory (8 个答案) 关闭
我使用的第三方库很好,但不会按照我想要的方式处理不存在的文件。当给它一个不存在的文件时,而不是提高旧的 FileNotFoundError: [Errno 2] No such file or dir
我已经使用 matplotlib 制作了一个图形,现在我正在尝试使用 matplotlib.pyplot.savefig 将其保存到文件中 import matplotlib.pyplot as pl
您好,我正在关注 pygame 游戏代码,但出现以下错误并发布了一个问题。当我运行它时,屏幕弹出然后立即消失。背景颜色也没有保存就执行了。 (Mac 操作系统) import pygame pygam
刚刚回到Python,我正在尝试构建一个脚本来匹配文件名,重命名,压缩它们,然后最终构建一个控制文件(我还没有写过)。它适用于放置在目录中的文件,但最后我收到错误: FileNotFoundError
我在使用 Python 的 Mac OS X 中遇到了相当奇怪的竞争条件(我只测试过 Python 3.3)。我正在创建几个临时目录,向其中写入内容,然后清除它们。类似于 while running:
为什么下面的交互失败? (Python 3.6.1) >>> with open('an_image.png', 'rb') as f, open('~/Desktop/an_image.png',
img = printscreen_pil img = img.filter(ImageFilter.MedianFilter()) enhancer = ImageEnhance.Contrast(
使用 unittest 模块,如何测试打开文件时引发的 FileNotFoundError,如下所示: func(filename): try: file = open(fil
我是一名优秀的程序员,十分优秀!