Errno 13,尝试读取文件时权限被拒绝

问题描述 投票:3回答:2

我创建了一个小的python脚本。有了这个,我试图读取一个txt文件但我的访问被拒绝解决为no.13错误,这是我的代码:

import time
import os

destPath = 'C:\Users\PC\Desktop\New folder(13)'
for root, dirs, files in os.walk(destPath):

f=open(destPath, 'r')
.....
python file readfile dir
2个回答
5
投票

根据名称,我猜测destPath是一个目录,而不是一个文件。你可以在目录上做一个os.walkos.listdir,但你不能用open来阅读。你只能在文件上调用open

也许你打算在open的一个或多个项目上打电话给files


-1
投票

尝试在路径-C:/ Users / anshu / Documents / Python_files / Test_files中创建文件时遇到此问题。我发现python无法真正访问用户名下的目录。所以,我尝试在目录-C:/ Users / anshu / Desktop下创建文件。我能够通过python在这个目录中创建文件,没有任何问题。

© www.soinside.com 2019 - 2024. All rights reserved.