【问题标题】:TypeError: object of type 'instancemethod' has no len() in NLTK [duplicate]TypeError:“instancemethod”类型的对象在 NLTK 中没有 len() [重复]
【发布时间】:2016-03-26 09:06:36
【问题描述】:

我正在尝试使用 Python 在终端中运行这段代码:

>>> from nltk.corpus import wordnet
>>> syn = wordnet.synsets('cookbook')[0]
>>> lemmas = syn.lemmas
>>> len(lemmas)

结果出现了错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object of type 'instancemethod' has no len()

出了什么问题以及如何解决这个问题?

【问题讨论】:

标签: python nltk


【解决方案1】:

要调用方法lemmas,附加()

>>> lemmas = syn.lemmas()
                       ↑↑

【讨论】:

  • 这行得通!非常感谢!
猜你喜欢
  • 2019-01-06
  • 2020-04-18
  • 1970-01-01
  • 2015-08-21
  • 2019-05-23
  • 2013-04-18
  • 2015-01-21
  • 2021-12-19
  • 2018-08-26
相关资源
最近更新 更多