【问题标题】:Spacy Module name is keywordSpacy 模块名称是关键字
【发布时间】:2020-05-11 11:59:04
【问题描述】:

我需要从spacy.lang.is 导入spacy 语言类。但是,is 是 python 中的一个关键字,因此我在 PyCharm IDE 中遇到了冲突。有没有办法解决这些问题?

【问题讨论】:

    标签: python python-3.x namespaces keyword spacy


    【解决方案1】:

    spacy docs建议导入如下:

    from spacy.lang.is import Icelandic
    nlp = Icelandic()
    

    这应该避免重新分配保留关键字is。

    如果这仍然让 PyC​​harm 抱怨,您可以使用 __import__:

    Icelandic = __import__('spacy.lang.is', globals(), locals(), ['Icelandic'], 0).Icelandic
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-06
      • 1970-01-01
      • 1970-01-01
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 2018-09-04
      • 2017-07-19
      相关资源
      最近更新 更多