Re: Python equivalents to MATLAB str2func, func2str, ischar, isfunc?
"dmitrey" <openopt@ukr.ne twrites:
I can't find these via web serch
>
thank you in advance,
Dmitrey
str2func: getattr(some_mo dule, 'f')
func2str: f.__name__
ischar: isinstance(x, basestring) and len(x) == 1
isfunc: callable(x) # is most likely to be what you want
Re: Python equivalents to MATLAB str2func, func2str, ischar, isfunc?
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(para m, 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...@gma il.comwrote:
"dmitrey" <open...@ukr.ne twrites:
I can't find these via web serch
>
thank you in advance,
Dmitrey
>
str2func: getattr(some_mo dule, 'f')
func2str: f.__name__
ischar: isinstance(x, basestring) and len(x) == 1
isfunc: callable(x) # is most likely to be what you want
>
'as
Re: Python equivalents to MATLAB str2func, func2str, ischar, isfunc?
"dmitrey" <openopt@ukr.ne twrites:
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(para m, 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?)
Comment