【发布时间】:2020-05-17 05:32:39
【问题描述】:
试图写一个命令行函数,我被这个 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'
我真的不知道出了什么问题,这让我把头发扯下来了。任何帮助都非常感谢,谢谢。
【问题讨论】:
标签: python namespaces argparse