import os
Current_Directory = os.getcwd() # Should be ...\archive
CORPUS_PATHS = sorted([os.path.join("archive", directories) for directories in os.listdir(Current_Directory)])
filenames = []
for items in CORPUS_PATHS:
filenames.append(sorted([os.path.join(CORPUS_PATHS, fn) for fn in os.listdir(items)]))
print filenames
Run Code Online (Sandbox Code Playgroud)
我正在从一个名为archive的文件运行此代码,并且在archive中有更多文件夹,并且在每个这些文件夹中都有一个或多个文本文件。我要创建一个列表,其中包含每个这些文件夹的路径。但是,出现以下错误。
[Error 3] The system cannot find the path specified:
Run Code Online (Sandbox Code Playgroud)
我目前有python脚本,在该脚本中,我在与存档相同的文件夹中编写了此代码,它将触发此错误。我应该怎么做才能停止此错误并获取所有文件路径。
我不太擅长使用os,而且我不经常使用它,因此,如果这是一个琐碎的问题,我深表歉意。
import os
startpath = "archive"
corpus_path = sorted([os.path.join("archive/", directories) for directories in os.listdir(startpath)])
filenames = []
for items in corpus_path:
print items
path = [os.path.join(corpus_path, fn) for fn in os.listdir(items)]
print path
Run Code Online (Sandbox Code Playgroud)
所以我取得了一些进展,现在我的语料库路径实质上是一个包含所有所需文件夹路径的列表。现在,我要做的就是获取这些文件夹中文本文件的所有路径,但是我仍然遇到问题,我不知道如何解决,但是出现诸如
File "C:\Users\David\Anaconda\lib\ntpath.py", …Run Code Online (Sandbox Code Playgroud) 我想识别句子中使用的动词,并确定该动词是用于字面意义还是比喻意义。我想我应该使用 VerbNet 和 NLTK。但是,我从未使用过 VerbNet。我该如何开始?