尝试编写命令行函数时,我被这个AttributeError阻止了。我知道其他人也问过类似的问题,但我没有看到任何人在使用plac,所以我想我应该把这个写出来
@plac.annotations(
training_file=("The filename containing the text you wish to annotate", "option", "-tf", Path),
entity_type=("The name of the entity you wish to annotate", "option", "-e", str)
)
def main(training_file=None, entity_type=None):
"""Script to more easily annotate spaCy NER training examples"""
if not training_file:
training_file = input("Please enter the filename of the data you wish to annotate: ")
with open(training_file, 'r') as training_file:
list_to_annotate = training_file.read()
print(list_to_annotate)
以及它运行的位置:
if __name__ == "__main__":
plac.call(main)
我的实际命令还有更多内容,但每当我运行此命令时,都会收到相同的错误消息:
Traceback (most recent call last):
File "C:\Users\Steve\PycharmProjects\GroceryListMaker\model_scripts\training_data_maker.py", line 79, in <module>
plac.call(main)
File "C:\Users\Steve\PycharmProjects\GroceryListMaker\lib\site-packages\plac_core.py", line 367, in call
cmd, result = parser.consume(arglist)
File "C:\Users\Steve\PycharmProjects\GroceryListMaker\lib\site-packages\plac_core.py", line 230, in consume
args = [getattr(ns, a) for a in self.argspec.args]
File "C:\Users\Steve\PycharmProjects\GroceryListMaker\lib\site-packages\plac_core.py", line 230, in <listcomp>
args = [getattr(ns, a) for a in self.argspec.args]
AttributeError: 'Namespace' object has no attribute 'training_file'
我真的不确定到底出了什么问题,这让我在这里毛骨悚然。非常感谢您的帮助,谢谢
如果将其替换为:
它可以工作(注意,我删除了缩写中的
-
)将来,您可以使用pdb更快地跟踪此类问题。以下是我所做的:
在这里,您可以看到您的参数名称空间被替换为
e
和tf
,这表明在缩写中添加-
实际上替换了参数名称(这只是我的猜测,但结果是正确的)我认为这是PATC的一个bug,它非常混乱,文档没有任何说明。p>
相关问题 更多 >
编程相关推荐