Python'builtin_function_or_method'对象没有属性'__getitem__'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22418242/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python 'builtin_function_or_method' object has no attribute '__getitem__'
提问by hmpk
Im trying to test out some stuff so I can make a python text adventure, but its not working. Here is the code:
我试图测试一些东西,以便我可以进行 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"
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?
我做错了什么,我该如何解决?
采纳答案by Scott Hunter
To call a method (like append), you wrap the parameters in () not [].
要调用方法(如append),请将参数包装在 () 而不是 [] 中。
回答by Evering Application
You have to do:
你必须要做:
if (int(calories) < 10):
print "YOU ARE FAT"
回答by Victor Lv
I also met this problem ever, and I found that the reason is that I wrote []after function invoke wrongly:
我也遇到过这个问题,我发现原因是我[]在function invoke之后写错了:
f.pop[para1] // wrong
f.pop(para1) // correct
Just change []into ()and program can work.
只需更改[]为()程序即可运行。

