简体   繁体   English

Python 3.5:FileNotFoundError:[Errno 2]没有这样的文件或目录

[英]Python 3.5: FileNotFoundError: [Errno 2] No such file or directory

I learned Python but hadn't used it in a few months so I am perhaps rusty. 我学会了Python,但是几个月没有使用它了,所以我可能会生锈。 I am just trying to start a project by reading from a csv text file. 我只是想通过从csv文本文件读取来启动项目。 I understand that there are several questions on this site about this error, but I haven't found one that fixes the issue. 我了解这个网站上有几个关于此错误的问题,但是我没有找到解决该问题的方法。 This is probably really basic and I wanted to figure this out without posting a question, but after several hours I really don't get it. 这可能真的很基础,我想在不发布问题的情况下解决这个问题,但是几个小时后,我真的不明白。 Sorry if I missed a question that has answered this, but I have checked a lot of questions first. 抱歉,如果我错过了回答了这个问题的问题,但我首先检查了很多问题。 Here is all of my code: 这是我所有的代码:

import csv
with open('C:\\Users\\Ben.Brittany-PC\\Documents\\stats.txt', 'rb') as csvfile:
    reader = csv.reader(csvfile, delimiter=' ', quotechar='|')
    for row in reader:
        print(row)

and the error: 和错误:

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Ben.Brittany-PC\\Documents\\stats.txt'

I'd guess it's the backslashes. 我猜这是反斜线。 Have you tried adding an r in front on your path to make r'C:\\Users\\Ben.Brittany-PC\\Documents\\stats.txt', 'rb' ? 您是否尝试过在路径的前面添加r以使r'C:\\ Users \\ Ben.Brittany-PC \\ Documents \\ stats.txt','rb'? This will make the string be read raw and backslashes will not need to be escaped. 这将使该字符串被读取为原始字符串,并且不需要转义反斜杠。

The file C:\\Users\\Ben.Brittany-PC\\Documents\\stats.txt does not exist. 文件C:\\ Users \\ Ben.Brittany-PC \\ Documents \\ stats.txt不存在。 Check the path (case sensitive). 检查路径(区分大小写)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python:FileNotFoundError:[Errno 2]没有这样的文件或目录 - python: FileNotFoundError: [Errno 2] No such file or directory Python FileNotFoundError:[错误2]没有这样的文件或目录 - Python FileNotFoundError: [Errno 2] No such file or directory Python FileNotFoundError: [Errno 2] 没有这样的文件或目录: - Python FileNotFoundError: [Errno 2] No such file or directory: FileNotFoundError: [Errno 2] 没有这样的文件或目录 [Python] - FileNotFoundError: [Errno 2] No such file or directory [Python] Python 3-FileNotFoundError:[Errno 2]没有这样的文件或目录 - Python 3 - FileNotFoundError: [Errno 2] No such file or directory FileNotFoundError: [Errno 2] 没有这样的文件或目录 Azure Python 错误 - FileNotFoundError: [Errno 2] No such file or directory Azure Python error Python 错误:FileNotFoundError: [Errno 2] 没有那个文件或目录 - Python error: FileNotFoundError: [Errno 2] No such file or directory FileNotFoundError:[Errno 2] Python 3.7 上的图片没有此类文件或目录 - FileNotFoundError: [Errno 2] No such file or directory for pictures on Python 3.7 Python 错误 FileNotFoundError: [Errno 2] 没有这样的文件或目录: - Python error FileNotFoundError: [Errno 2] No such file or directory: FileNotFoundError: [Errno 2] 没有这样的文件或目录 (Python 3.10) - FileNotFoundError: [Errno 2] No such file or directory (Python 3.10)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM