python - 为什么我在尝试打开 Excel 文件时收到“PermissionError: [Errno 13] Permission denied”?
问题描述
您好我正在尝试在 python 中访问一个 excel 文件。我正在使用我们在课堂上学到的这段代码:
with open("file_name") as csv_file:
csv_reader =csv.DictReader(csv_file)
每次我运行它我都会得到同样的错误
PermissionError: [Errno 13] Permission denied: 'file_name'
是否有任何我可以运行的代码允许命令 shell 读取文件?
解决方案
您需要file_name
使用正确的路径和文件名进行更改,即:
import csv
with open("/home/user/path/to/file.csv") as csv_file:
csv_reader = csv.DictReader(csv_file)
对于 windows 将如下所示:
import csv
with open("c:\\path\\to\\file.csv") as csv_file:
csv_reader = csv.DictReader(csv_file)
推荐阅读
- oracle - 创建用于计数的光标
- node.js - 获取位于特定 S3 文件夹下的对象列表
- css - 如何仅将外部 CSS 应用到特定区域
- javascript - 清除表单时出现 Vue + Vuetify 验证问题
- filter - ffmpeg - 如何在同时录制窗口应用程序时过滤视频
- python - 在点击中弃用参数别名的正确方法
- javascript - jQuery ajax async 'true' 让我的网络应用程序卡住,直到数据返回
- android - 无法在 sdk 更新站点中更新存储库
- c# - C# 更新网络适配器名称部分工作(WinReg 好,ipconfig 坏)
- android - Base.Widget.Design.TabLayout 不能作为 android 中 style.xml 中的父级