Python' builtin_function_or_method'对象没有属性' __ getitem __'

时间:2014-03-15 00:59:08

标签: python

我试图测试一些东西,所以我可以进行python文本冒险,但它不起作用。这是代码:

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"

但是我收到了这个错误:

'builtin_function_or_method' object has no attribute '__getitem__'

我做错了什么,我该如何解决?

3 个答案:

答案 0 :(得分:4)

要调用方法(如append),请将参数包装在()而不是[]。

答案 1 :(得分:1)

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.

答案 2 :(得分:0)

你必须这样做:

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