当我测试我的代码时:
def read_classification_from_file(path, name):
path = add_slash(path) + name
myfile = open(path, "r")
mydict = {}
for line in myfile():
x = line.split(" ")
x[1]=x[1].replace("\n","")
mydict[x[0]]=x[1]
return mydict
def add_slash(path):
if path.endswith('/'): return path
return path + '/'
我收到错误:
Traceback (most recent call last):
File "spamfilter/solution/test_quality_for_corpus.py", line 59, in test_allPredictionsHam
q = self.compute_quality_for_corpus(CORPUS_DIR)
File "/local/ulohy/env/data/4893_1/quality.py", line 9, in compute_quality_for_corpus
truth_dic = utils.read_classification_from_file(corpus_dir, "!truth.txt")
File "/local/ulohy/env/data/4893_1/utils.py", line 5, in read_classification_from_file
for line in myfile():
TypeError: '_io.TextIOWrapper' object is not callable
所以,我只是字体明白,错误在哪里。
谢谢!