473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

I can't find these via web serch

thank you in advance,
Dmitrey

Mar 14 '07 #1
4 8886
"dmitrey" <op*****@ukr.netwrites:
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
Mar 14 '07 #2
dmitrey wrote:
I can't find these via web serch
You won't find exact equivalents. But, the same functionality is
available. Perhaps you would like to show us what you are trying to do
in Python.

Python's eval has some similarity with str2func

Python's repr() or str() has some similarity with func2str

ischar(A) is similiar to isinstance(A, str)

isfunc is similiar to callable

-Travis

P.S. (if you are using NumPy, then there are other possibilities as well.

Mar 14 '07 #3
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...@gmail.comwrote:
"dmitrey" <open...@ukr.netwrites:
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

Mar 14 '07 #4
"dmitrey" <op*****@ukr.netwrites:
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
Mar 14 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Carl | last post by:
I have been using Python for quite some time now and I love it. I use it mainly for explorative computing and numerical prototyping, ie testing and trying out different kinds of algorithms and...
3
by: Ali | last post by:
How to use python in matlab?
4
by: dataangel | last post by:
I'm a student who's considering doing a project for a Machine Learning class on pathing (bots learning to run through a maze). The language primarily used by the class has been Matlab. I would...
19
by: Nicolas Pernetty | last post by:
Hello, I'm looking for any work/paper/ressource about continuous system simulation using Python or any similar object oriented languages (or even UML theory !). I'm aware of SimPy for...
53
by: Michael Tobis | last post by:
Someone asked me to write a brief essay regarding the value-add proposition for Python in the Fortran community. Slightly modified to remove a few climatology-related specifics, here it is. I...
9
by: Carl | last post by:
I am desperately looking for a way to call Python from Matlab. I have become used to Python's rich syntax and large number of libraries, and feel ridiculously clumsy being stuck with Matlab's...
8
by: Allen | last post by:
Does anyone agree with me? If you have used Matlab, welcome to discuss it.
4
by: wang frank | last post by:
Hi, While comparing the speed of octave and matlab, I decided to do a similar test for python and matlab. The result shows that python is slower than matlab by a factor of 5. It is not bad since...
4
by: itcecsa | last post by:
Hi, I am implementing a small Python project, what I am going to do is to open Matlab and run some M-files, and get some output from Matlab command prompt. I have no idea how to open Matlab...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.