我正在尝试修改GitHub的一个脚本,该脚本将访问TAR文件并对其进行处理。代码中有一个变量需要指向文件所在的根目录(我认为…)。代码如下:
def make_Dictionary(root_dir):
emails_dirs = [os.path.join(root_dir,f) for f in os.listdir(root_dir)]
all_words = []
for emails_dir in emails_dirs:
emails = [os.path.join(emails_dir,f) for f in os.listdir(emails_dir)]
for mail in emails:
with open(mail) as m:
for line in m:
words = line.split()
all_words += words
dictionary = Counter(all_words)
list_to_remove = dictionary.keys()
for item in list_to_remove:
if item.isalpha() == False:
del dictionary[item]
elif len(item) == 1:
del dictionary[item]
dictionary = dictionary.most_common(4000)
np.save('dict_movie.npy',dictionary)
return dictionary
root_dir = sys.path[0]
dictionary = make_Dictionary(root_dir)
root\u dir正在抛出:
File "C:\Users\seand\eclipse-workspace\sentiment_project\src\root\nested\movie-polarity.py", line 22, in make_Dictionary
emails = [os.path.join(emails_dir,f) for f in os.listdir(emails_dir)]
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\\Users\\seand\\eclipse-workspace\\sentiment_project\\src\\root\\nested\\movie-polarity-tfidf.py'
方向状态“注意:需要相应地设置movie-polarity-tfidf.py和movie-polarity.py中语料库的目录路径。”但我指定的路径包含脚本所需的语料库TAR文件。我不明白为什么,如果脚本正在查找目录,那么这个.py文件会被拾取。