Python equivalents to MATLAB str2func, func2str, ischar, isfunc?

Alexander Schmolck a.schmolck at gmail.com
Wed Mar 14 14:33:51 EDT 2007


"dmitrey" <openopt at ukr.net> writes:

> Thank you
> (however in MATLAB ischar is the same as isstr)

Right, sorry.

> but what if I don't know the name of module?
> I.e. I have
> 
> def myfunc(param): ...
> #where param can be both funcName or a function, and I want to obtain
> both name and func, something like
> if isinstance(param, basestring):
>    func, funcName = <something>, param
> else: func, funcName = param, param.__name__
> what should I type instead of <something>?

globals()[param] (I assume you don't want a local function, should one exist?)

'as



More information about the Python-list mailing list