[SciPy-user] Newbie Question about Scipy

Ryan Krauss ryanlists@gmail....
Wed Feb 14 10:07:32 CST 2007


Hey Lorenzo,

Your question has to do with a feature of Python called namespaces.
This can be a little vague and weird to the newcomer, but it is a
great strength of Python.  It is also very necessary because there are
so many people writing so many modules for Python.  Namespaces allow
two different modules to have functions with the same name without
conflicting with one another.  So, if module1 and module2 both have
functions called sqrt, module1.sqrt and module2.sqrt can be two
different functions.  Using from module1 import * will load that
module's sqrt into the global namespace.  This may seem weird, but
trust me, it is a good thing.  If you googled for "python namespaces"
you might get a better explanation.  There is an in-depth discussion
of the concept in the book "Learning Python" by Mark Lutz - most
libraries should have it.

The question about how python (or better
scipy/numpy/matplotlib/ipython) compares with Matlab or Octave will
start a war if asked in the wrong places.  Most people on this list
will tell you stories similar to mine: I switched from Matlab to
Python midway through my Ph.D. work and it was one of the best
decisions I ever made.  I find writing Python code so much faster and
easier that I enjoy it quite a bit.  I think the only risk is that if
you are closely attached to some Matlab toolbox that doesn't yet exist
in Python/Scipy and friends, you will need to go through the learning
process of writing some things yourself.  Fortunately, Python and the
number of existing modules make this process not so bad.

Ryan

On 2/14/07, Lorenzo Isella <lorenzo.isella@gmail.com> wrote:
> Dear All,
> I am pretty new to Python, but it has such a good reputation that I
> decided to give it a try.
> I am slightly puzzled about the syntax modulename.function.
> I am going through the SciPy tutorial by Oliphant (btw, is there
> anywhere online a free updated version of a document of this kind?).
> To use SciPy I normally do the following:
>
> ~$ ipython
> Python 2.4.4 (#2, Jan 13 2007, 17:50:26)
> Type "copyright", "credits" or "license" for more information.
>
> IPython 0.7.3 -- An enhanced Interactive Python.
> ?       -> Introduction to IPython's features.
> %magic  -> Information about IPython's 'magic' % functions.
> help    -> Python's own help system.
> object? -> Details about 'object'. ?object also works, ?? prints more.
>
> In [1]: from scipy import *
>
> However, statements like the ones in the guide:
>
> In [12]: from integrate import quad
> ---------------------------------------------------------------------------
> exceptions.ImportError                               Traceback (most
> recent call last)
>
> /home/iselllo/<ipython console>
>
> ImportError: No module named integrate
>
> do not work.
> So I have to use: scipy.integrate. Similarly, the function gamma is
> not recognized, but special.gamma is.
> How is this chosen by the system? Then: once I have import everything
> from scipy, is importing explicitly the gamma function a necessity at
> all?
> ****************************************************************************
> On a more general ground, how does Python compare with e.g. MatLab or
> Octave for scientific computing? Which are the advantages and
> drawbacks (sorry if this is not the right forum).
> Kind Regards
>
> Lorenzo
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>


More information about the SciPy-user mailing list