sebastizz
asked on
TypeError: 'list' object is not callable in python
Im trying to run the following code in python
from nltk.corpus import wordnet as wn
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
TypeError: 'list' object is not callable
What am I doing wrong?
from nltk.corpus import wordnet as wn
for i in wn.all_synsets():
if i.pos() in ['a', 's']: # If synset is adj or satelite-adj.
for j in i.lemmas(): # Iterating through lemmas for each synset.
if j.antonyms(): # If adj has antonym.
# Prints the adj-antonym pair.
print j.name(), j.antonyms()[0].name()
This should give me a complete list of opposite words from wordnet. Unfortunately instead of this i get this error:Traceback (most recent call last):
File "<stdin>", line 2, in <module>
TypeError: 'list' object is not callable
What am I doing wrong?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Don't I get any credit for my "drop the parentheses" comment?
ASKER
Good answer
ASKER
OK tried that and also getting rid of the () after lemmas so that the code now looks like:
from nltk.corpus import wordnet as wn
for i in wn.all_synsets():
if i.pos in ['a', 's']:
for j in i.lemmas:
if j.antonyms():
print j.name(), j.antonyms()[0].name()
but now I get the error:
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
TypeError: 'str' object is not callable
Any ideas?