繁体   English   中英

Python'builtin_function_or_method'对象没有属性'__getitem__'

[英]Python 'builtin_function_or_method' object has no attribute '__getitem__'

我正在尝试测试一些东西,以便可以进行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__'

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

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

我也曾经遇到过这个问题,我发现原因是我在函数错误调用之后写了[]

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

只需将[]更改为() ,程序就可以工作。

你必须做:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM