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

dmitrey openopt at ukr.net
Wed Mar 14 13:17:05 EDT 2007


Thank you
(however in MATLAB ischar is the same as isstr)
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>?

D.



On Mar 14, 7:06 pm, Alexander Schmolck <a.schmo... at gmail.com> wrote:
> "dmitrey" <open... at ukr.net> writes:
> > I can't find these via web serch
>
> > thank you in advance,
> > Dmitrey
>
> str2func: getattr(some_module, 'f')
> func2str: f.__name__
> ischar: isinstance(x, basestring) and len(x) == 1
> isfunc: callable(x) # is most likely to be what you want
>
> 'as





More information about the Python-list mailing list