Python 3.x FileNotFoundError:[Errno 2]没有这样的文件或目录:';C:\\Users\\mswitajski\\Desktop\\alice.txt';

Python 3.x FileNotFoundError:[Errno 2]没有这样的文件或目录:';C:\\Users\\mswitajski\\Desktop\\alice.txt';,python-3.x,directory,errno,file-not-found,word-cloud,Python 3.x,Directory,Errno,File Not Found,Word Cloud,我正在尝试读取文本文件以处理Word Clouds。以下是我正在尝试的语法: # Read the whole text. text = open(r'C:\Users\mswitajski\Desktop\alice.txt').read() 但我一直得到以下错误: FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\mswitajski\\Desktop\\alice.txt' 我已经三次检查了文件名,尝

我正在尝试读取文本文件以处理Word Clouds。以下是我正在尝试的语法:

# Read the whole text.
text = open(r'C:\Users\mswitajski\Desktop\alice.txt').read()
但我一直得到以下错误:

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\mswitajski\\Desktop\\alice.txt'

我已经三次检查了文件名,尝试将其作为原始文件读取,更改了斜杠和所有内容,但仍然出现相同的错误。

尝试更改此文件的路径”

'C:\Users\mswitajski\Desktop/alice.txt'

当文件被这样指定时,windows有时无法找到/识别文件路径

'C:\Users\mswitajski\Desktop\alice.txt'


在答案中,它只显示为一个\但您仍然需要与上一条路径相同的2个。唯一的区别是最后一个斜杠/。希望有效。

尝试更改此路径”

'C:\Users\mswitajski\Desktop/alice.txt'

当文件被这样指定时,windows有时无法找到/识别文件路径

'C:\Users\mswitajski\Desktop\alice.txt'

在答案中,它只显示为一个\但您仍然需要2个,就像前面的路径一样。唯一的区别是最后一个斜杠/。希望能奏效。

在文本原始文件(alice.txt)中尝试删除.txt。 该文件可能名为alice.txt.txt 我面临同样的问题,并通过删除.txt来解决它。

在您的文本原始文件(alice.txt)中尝试删除.txt。 该文件可能名为alice.txt.txt
我面临同样的问题,并通过删除.txt来解决它。

我不得不使用双斜杠而不是一个斜杠,因为python将其解释为转义序列。我的最后一句话是:

C:\\Users\\ArpitChinmay's\\AppData\\Roaming\\Code\\User\\globalStorage\\moocfi.test-my- 
code\\tmcdata\\TMC workspace\\Exercises\\hy\\hy-data-analysis-with-python- 
2020\\part02-e04_word_frequencies\\src\\alice.txt
但它也是这样运作的,

C:\\Users\\Arpit Chinmay's\\AppData\\Roaming\\Code\\User\\globalStorage\\moocfi.test- 
my-code\\tmcdata\\TMC workspace\\Exercises\\hy\\hy-data-analysis-with-python- 
2020\\part02-e04_word_frequencies\\src/alice.txt

我不得不使用双斜杠而不是一个,因为python将其解释为转义序列。我的最后一句话是:

C:\\Users\\ArpitChinmay's\\AppData\\Roaming\\Code\\User\\globalStorage\\moocfi.test-my- 
code\\tmcdata\\TMC workspace\\Exercises\\hy\\hy-data-analysis-with-python- 
2020\\part02-e04_word_frequencies\\src\\alice.txt
但它也是这样运作的,

C:\\Users\\Arpit Chinmay's\\AppData\\Roaming\\Code\\User\\globalStorage\\moocfi.test- 
my-code\\tmcdata\\TMC workspace\\Exercises\\hy\\hy-data-analysis-with-python- 
2020\\part02-e04_word_frequencies\\src/alice.txt

但是它运行的用户有权访问该文件吗?是的,用户有权访问所有文件。但是它运行的用户有权访问该文件吗?是的,用户有权访问所有文件。我尝试过进行这些更改,但仍会收到相同的错误。我尝试过进行这些更改,但仍会收到相同的错误。但请确保在此之前复制了正确的源文件路径。有时文件名可能包含扩展名,例如“alice.txt”,因此它将作为alice.txt.txt保存在系统中,但请确保在此之前复制正确的源文件路径。有时文件名可能包含扩展名,例如“alice.txt”,因此它将作为alice.txt.txt保存在系统中