Interesting problem - can it be done

Ype Kingma ykingma at accessforall.nl
Thu Aug 9 17:22:13 EDT 2001


Mark,

you wrote:
> 
> Hi all,
>     I have a list of strings and the strings are functions that I want to
> call on an object.  How do I call the functions without hardcoding the
> function call?  Here is an example
> 
> funclist = ['func1()', 'func2()', 'func3()']
> x = len(funclist)
> y = 0
> while y < x:
>     value = testobj.funclist[y]
>     y = y +1
> 
> This way I could grow the list of functions to be called without coding more
> like the way I am doing it now. I would like to avoid doing the following:
> 
> value = testobj.func1()
> value = testobj.func2()
> value = testobj.func3()
> 

All the getattr() stuff is great. For testing it has been
coded for you in PyUnit.py. It will do your while loop (above),
administer your test results and a lot more, when you are willing
to declare your test methods in a subclass of an
imported testing base class. Elaborate example:

http://diveintopython.org/roman_divein.html

You can get it here:

http://pyunit.sourceforge.net/

Have fun,
Ype

-- 
email at xs4all.nl



More information about the Python-list mailing list