fromfunc functions

Chris cwitts at gmail.com
Wed Feb 13 12:05:37 EST 2008


On Feb 13, 5:51 pm, azrael <jura.gro... at gmail.com> wrote:
> I came across the fromfunc() function in numpy where you pass as an
> argument the name of a function as a string and also the atributes for
> the desired function.
>
> I find this extremly usefull and sexy. Can someone point me how write
> a function of such capabilities

class test_class():
    def test_func(self, string):
        print string

test = test_class()
getattr(test, 'test_class'){'this is the test argument')

getattr raises an Attribute Error though if the function doesn't exist
so you'll need to catch that.



More information about the Python-list mailing list