[英]Permission error in Jupiter notebook in Windows 10 while using os library in python [Errno 13]
The file of my jupyter notebook and the folder I have been trying to open are in the same folder.我的 jupyter notebook 的文件和我一直试图打开的文件夹在同一个文件夹中。
When running the following code (here, 'mbdataset' is the folder I am trying to open):运行以下代码时(此处,“mbdataset”是我要打开的文件夹):
hf= open('mbdataset','r')
hc= hf.read()
hc
I am getting the following error:我收到以下错误:
PermissionError: [Errno 13] Permission denied: 'mbdataset'
Please tell me what I should do to avoid this.请告诉我应该怎么做才能避免这种情况。
Is "mbdataset" the actual filename? “mbdataset”是实际的文件名吗?
Depending on how you start your notebook, you might want to do:根据您启动笔记本的方式,您可能需要执行以下操作:
import os
os.getcwd()
To check your current working directory.检查您当前的工作目录。 You can set your working directory with:您可以使用以下命令设置工作目录:
os.chdir(path_to_dataset)
As your comment says, you try to open a folder with open()
正如您的评论所说,您尝试使用open()
打开一个文件夹
open()
expects a file. open()
需要一个文件。 So depending on your dataset, you might need to iterate through files, or read a json, to says this, more information is needed.因此,根据您的数据集,您可能需要遍历文件,或读取 json,也就是说,需要更多信息。
For example, you could do this:例如,您可以这样做:
import glob
files = []
for file in glob.glob("/mbdataset/*.(txt for example)"):
text = open(file, "r")
files.apped(text.read())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.