IOError: [Errno 13] when specifying path for functions
IOError: [Errno 13] when specifying path for functions
我正在制作一个搜索引擎,我需要一些帮助来清除我选择要搜索的文件夹的代码。
我让用户用这个函数指定一个路径:
def location_specify():
location = raw_input('Define path for search: ')
return location
location = location_specify()
这个位置我用于以下功能,我想在其中打开文件夹中的文档并标记化。
def open_doc(location):
docfile = codecs.open(location, 'r', encoding='utf-8')
doclist = docfile.read().lower().split()
docfile.close()
return doclist
我用这个路径测试了这个函数:
C:\Users\Vestergaard\Desktop\Informationssoegning\Ernaeringskorpus
我收到了这条错误消息
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
open_doc(location)
File "<pyshell#15>", line 2, in open_doc
docfile = codecs.open(location, 'r', encoding='utf-8')
File "C:\Python27\lib\codecs.py", line 884, in open
file = __builtin__.open(filename, mode, buffering)
IOError: [Errno 13] Permission denied: 'C:\Users\Vestergaard\Desktop\Informationssoegning\Ernaeringskorpus'
我不知道我做错了什么。可能是我的功能有问题?
import codecs, os
def open_doc(directory):
allfiles = {}
for filename in os.listdir(directory):
docfile = codecs.open(os.path.join(directory, filename), 'r', encoding='utf-8')
content = docfile.read().lower().split()
docfile.close()
allfiles[filename] = content
return allfiles
我正在制作一个搜索引擎,我需要一些帮助来清除我选择要搜索的文件夹的代码。
我让用户用这个函数指定一个路径:
def location_specify():
location = raw_input('Define path for search: ')
return location
location = location_specify()
这个位置我用于以下功能,我想在其中打开文件夹中的文档并标记化。
def open_doc(location):
docfile = codecs.open(location, 'r', encoding='utf-8')
doclist = docfile.read().lower().split()
docfile.close()
return doclist
我用这个路径测试了这个函数:
C:\Users\Vestergaard\Desktop\Informationssoegning\Ernaeringskorpus
我收到了这条错误消息
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
open_doc(location)
File "<pyshell#15>", line 2, in open_doc
docfile = codecs.open(location, 'r', encoding='utf-8')
File "C:\Python27\lib\codecs.py", line 884, in open
file = __builtin__.open(filename, mode, buffering)
IOError: [Errno 13] Permission denied: 'C:\Users\Vestergaard\Desktop\Informationssoegning\Ernaeringskorpus'
我不知道我做错了什么。可能是我的功能有问题?
import codecs, os
def open_doc(directory):
allfiles = {}
for filename in os.listdir(directory):
docfile = codecs.open(os.path.join(directory, filename), 'r', encoding='utf-8')
content = docfile.read().lower().split()
docfile.close()
allfiles[filename] = content
return allfiles