an apply question

Darrell Gallion darrell at dorb.com
Tue Dec 5 19:06:59 EST 2000


>>> def a():
...     print 'a'
...
>>> myMap={'a':a}
>>> for k, f in myMap.items():
...     apply(f,())
...
a
>>>

func1 in MyMap shouldn't be a string.

--Darrell

----- Original Message ----- 
From: "Alan Marchand" <malan at club-internet.fr>
> In Python 2.0:
> 
> What am I doing wrong?
> 
> #!/bin/env python
> #############
> MyMap = {
> 'Key1' : 'func1',
> 'Key2' : 'func2',
> 'Key3' : 'func3',
> 'Key4' : 'func4'
> }
> 
> def func1 ( ):
>     print "Here's func1"
> 
> items = MyMap.items( )
> for x in range( len(items) ):
>     key, func = items[x]
>     if key == "Key3":
>         apply( func, ( ) )
> -------------------------
> c:\devpy\python test.py
> 
> Traceback (most recent call last):
>   File "test.py", line 17, in ?
>     apply( func, ( ) )
> TypeError: Call of non-function (type string)






More information about the Python-list mailing list