On Wed, Dec 7, 2011 at 7:41 PM, Anand Patil <[email protected]> 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
failure.
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:
lis={"a":[getabc,gettuple,getlist]}
reg,
sateesh
_______________________________________________
BangPypers mailing list
[email protected]
http://mail.python.org/mailman/listinfo/bangpypers