programmatically calling a function
Doug Schwarz
see at sig.for.address.edu
Sat Mar 5 09:28:49 EST 2005
In article <2005030418250516807%dekhaus at maccom>,
Dave Ekhaus <dekhaus at mac.com> wrote:
> hi
>
> i'd like to call a python function programmatically - when all i have
> is the functions name as a string. i.e.
>
>
> fnames = ['foo', 'bar']
>
> for func in fnames:
>
> #
> # how do i call function 'func' when all i have is the name of the
> function ???
> #
>
>
>
> def foo():
>
> print 'foo'
>
> def bar():
>
> print 'bar'
>
>
> i'd really appreciate any help the 'group' has to offer.
>
>
> thanks
> dave
Dave,
I think eval might be what you're looking for:
f = eval('len')
length = f([1,2,3])
By the way, are you the Dave Ekhaus I used to work with at Kodak?
--
Doug Schwarz
dmschwarz&urgrad,rochester,edu
Make obvious changes to get real email address.
More information about the Python-list
mailing list