我正在执行代码
Set rsAccountNumber = CurrentDb.OpenRecordset("SELECT DISTINCT AccountNumber, email_address1 FROM [P3_DVP_UnAffirmed_Report_for_En Query]",dbOpenSnapShot)
NaiveBayes模块包含具有功能import sys
sys.path.append('/home/stepfourward/naivebayes/Naive-Bayes/')
from NaiveBayes import *
import os
DClasses = ["python", "java", "hadoop", "django", "datascience", "php"]
base = "learn/"
p = Pool()
for i in DClasses:
p.learn(base + i, i)
的{{1}}:
Pool.py
但是当我应用上面代码中提到的方法learn()
时,出现属性错误。
def learn(self, directory, dclass_name):
"""
directory is a path, where the files of the class with the name dclass_name can be found
"""
x = DocumentClass(self.__vocabulary)
dir = os.listdir(directory)
for file in dir:
d = Document(self.__vocabulary)
print(directory + "/" + file)
d.read_document(directory + "/" + file, learn=True)
x = x + d
self.__document_classes[dclass_name] = x
x.SetNumberOfDocs(len(dir))
如何消除此错误。谢谢。
答案 0 :(得分:0)
按照elsewhere的解释,在文件夹Naive-Bayes
中克隆了存储库后,以下是使用上述NaiveBayes库的正确步骤:
你做什么
import sys
sys.path.append('Naive-Bayes/') # your own path here
from NaiveBayes import * # NO error here
p = Pool()
产生错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Pool' is not defined
您应该做什么:
import sys
sys.path.append('Naive-Bayes/')
from NaiveBayes.Pool import Pool # correct import
p = Pool() # runs OK now
DClasses = ["python", "java", "hadoop", "django", "datascience", "php"]
base = "learn/"
for i in DClasses:
p.learn(base + i, i)
在这点(但不是在此之前),我收到了 expected 错误,原因仅仅是我的目录中没有您的目录(例如learn/python
)机器:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/home/herc/SO/Naive-Bayes/NaiveBayes/Pool.py", line 29, in learn
dir = os.listdir(directory)
FileNotFoundError: [Errno 2] No such file or directory: 'learn/python'
但明确的消息是Pool
中的learn
对象和Pool.py
方法确实可以访问。
在Ubuntu中使用Python 3.4.3进行了测试...