我正在学习Python文件对象,但每当我尝试打开文件时,它显示以下错误。
我已经检查过文件在同一个目录中存在。如果我将文件命名为“test”,则会出现此错误。使用其他名称则可以正常工作。下面是我的代码:
f = open('C:\\Users\Tanishq\Desktop\python tutorials\test.txt', 'r')
这里出现了错误。
Traceback (most recent call last):
File "C:/Users/Tanishq/Desktop/question.py", line 1, in <module>
f = open('C:\\Users\Tanishq\Desktop\python tutorials\test.txt', 'r')
OSError: [Errno 22] Invalid argument: 'C:\\Users\\Tanishq\\Desktop\\python
tutorials\test.txt'
\
,或者使用 原始字符串(即r'...'
)。 - 0x5453'C:\\\\Users\\Tanishq\\Desktop\\python tutorials\\test.txt'
),要么使用原始字符串字面值 (r'C:\\Users\Tanishq\Desktop\python tutorials\test.txt'
)。 - Gevorg Davoian