fromfunc functions

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Wed Feb 13 18:28:36 CET 2008


On Wed, 13 Feb 2008 07:51:36 -0800, azrael 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.

If you mean `fromfunction()` then you don't give the name of the function
as string but the function itself as argument.  And what you call
attributes are arguments.

> I find this extremly usefull and sexy. Can someone point me how write
> a function of such capabilities

Functions are objects in Python, you can pass them around like any other
object/value.

In [18]: def f(func, arg):
   ....:     return func(arg)
   ....:

In [19]: f(int, '42')
Out[19]: 42

In [20]: f(str.split, 'a b c')
Out[20]: ['a', 'b', 'c']

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list