[IPython-dev] [Enthought-dev] Control of names in the Pylab interactive namespace

Elston, Gareth R gelston@doosanbabcock....
Mon Oct 13 14:12:50 CDT 2008


I'm going to be giving an Introduction to Python presentation to a number
of engineering colleagues next week. I'll be demonstrating the capabilities
of Pylab and recommending the EPD as the best way to install all of the
required packages.

My questions are: where do I need to start looking for what happens when
IPython is called with the -pylab flag? Or how do I control which names
are included / excluded from the interactive namespace? My first example
was partly intended to show how useful the "whos" function is, but failed!
The Pylab sessions below demonstrate the problem.

I have epd_py25-4.0.30002_beta3-win32-x86.msi installed and was a little
surprised by the empty namespace (using whos) after trying the following
example:

Enthought Python Distribution (4.0.30001) -- http://code.enthought.com
Python 2.5.2 |EPD 4.0.3.0001| (r252:60911, Sep 18 2008, 17:54:39)
IPython 0.9.1 -- An enhanced Interactive Python.

In [1]: def f (x, a, b, c):
   ...:     """Quadratic function"""
   ...:     return a*x**2 + b*x + c
   ...:

In [2]: x = arange(-5, 5.1, 0.5)

In [3]: x
Out[3]:
array([-5. , -4.5, -4. , -3.5, -3. , -2.5, -2. , -1.5, -1. , -0.5,  0. ,
        0.5,  1. ,  1.5,  2. ,  2.5,  3. ,  3.5,  4. ,  4.5,  5. ])

In [4]: f(x,1,2,3)
Out[4]:
array([ 18.  ,  14.25,  11.  ,   8.25,   6.  ,   4.25,   3.  ,   2.25,
         2.  ,   2.25,   3.  ,   4.25,   6.  ,   8.25,  11.  ,  14.25,
        18.  ,  22.25,  27.  ,  32.25,  38.  ])

In [5]: whos
Interactive namespace is empty.

In a new Pylab session, I discovered that both f and x are already defined
during Pylab's initialisation, and presumably this is why they are excluded
from the interactive namespace:

In [1]: [name for name in dir() if len(name)==1]
Out[1]: ['_', 'e', 'f', 'x']

In [2]: e
Out[2]: 2.7182818284590451

In [3]: f
Out[3]: <built-in method f of mtrand.RandomState object at 0x00A6A310>

In [4]: x
Out[4]: 'symlog'

In [5]: f?
Type:           builtin_function_or_method
Base Class:     <type 'builtin_function_or_method'>
String Form:    <built-in method f of mtrand.RandomState object at 0x00A6A310>
Namespace:      Interactive
Docstring:
    F distribution.
f(dfnum, dfden, size=None) -> random values

I would like to find a way to put 'f' and 'x' back into the interactive
namespace, or find out where they are brought into the excluded namespace
so that I can try to fix the problem there.

More generally, if a name is exluded from the interactive namespace and is
then defined interactively, could this name be made to appear once again in
the interactive namespace?

Thanks,
Gareth.


-------------------------------------------------------------
IMPORTANT NOTICE.

This E-Mail and any files transmitted with it, are  confidential and may be
privileged and are for the exclusive use of the intended recipient(s).
If you are not the intended recipient(s) please note that any form 
of distribution, copying or use of this communication or the
information in it, is strictly prohibited and may be unlawful.

If you have received this E-Mail in error please return it to the sender.
We should be grateful if you would also copy the communication to
postmaster@doosanbabcock.com the delete the E-Mail and destroy any
copies of it.

It is your responsibility to scan any attachments for viruses.

For further information, visit us at WWW.DOOSANBABCOCK.COM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ipython.scipy.org/pipermail/ipython-dev/attachments/20081013/6d45b4a1/attachment.html 


More information about the IPython-dev mailing list