[BangPypers] BangPypers Digest, Vol 52, Issue 7

Sateesh Kumar sateeshpyper at gmail.com
Wed Dec 7 20:35:59 CET 2011

On Wed, Dec 7, 2011 at 7:41 PM, Anand Patil <2002anand at gmail.com> wrote:

> Hi.
> I have a unique question or may be i am not so perfect at python.Please
> help me out
> a, b, c = 0, 0, 0
> def getabc():
>    print "hi "
> def gettuple():
>    print "hello all"
> def getlist():
>    print "bye"
> lis={"a":["getabc","gettuple","getlist"]}
> lis['a'][1]()
> why does this fail ?

The  failure message that you get would give you a hint about reason for

You are storing a list of strings (the method names) as value for
dictionary key 'a'.
The invocation : lis['a'][1]() results in call similar to "gettuple"()
resulting in error: "TypeError: 'str' object is not callable".

What you intend to do is to store function objects in the list and
and you can do this as below:


More information about the BangPypers mailing list