hmpk
hmpk

Reputation: 43

Python 'builtin_function_or_method' object has no attribute '__getitem__'

Im trying to test out some stuff so I can make a python text adventure, but its not working. Here is the code:

calories = [3]

fooland= ("fooland")
area=fooland
joint= ("joint")

while area=="fooland":
talk=raw_input("Where to go?")

if talk==joint:
    area=joint

else:
    print "You cant do that!"


while area=="joint":
order=raw_input("What to order?")

if order=="fries":
    print "You eat like a BAWS"
    calories.append[2]

else:
    print "You cant eat that, but here is some grease!"
    calories.append[6]

 if [calories < 10]:
print "YOU ARE FAT"

But i get this error:

'builtin_function_or_method' object has no attribute '__getitem__'

What am i doing wrong and how can i fix it?

Upvotes: 3

Views: 24907

Answers (3)

Victor Lv
Victor Lv

Reputation: 81

I also met this problem ever, and I found that the reason is that I wrote []after function invoke wrongly:

 f.pop[para1]   // wrong 
 f.pop(para1)   // correct    

Just change [] into () and program can work.

Upvotes: 1

Evering Application
Evering Application

Reputation: 1

You have to do:

    if (int(calories) < 10):
      print "YOU ARE FAT"

Upvotes: 0

Scott Hunter
Scott Hunter

Reputation: 49805

To call a method (like append), you wrap the parameters in () not [].

Upvotes: 4

Related Questions