[Numpy-discussion] Synonym standards
Fri Jul 27 11:43:14 CDT 2012
On 27 Jul 2012, at 17:58, Tony Yu wrote:
> On Fri, Jul 27, 2012 at 11:39 AM, Derek Homeier <email@example.com> wrote:
> On 27.07.2012, at 3:27PM, Benjamin Root wrote:
> > > I would prefer not to use: from xxx import *,
> > >
> > > because of the name pollution.
> > >
> > > The name convention that I copied above facilitates avoiding the pollution.
> > >
> > > In the same spirit, I've used:
> > > import pylab as plb
> > But in that same spirit, using np and plt separately is preferred.
> > "Namespaces are one honking great idea -- let's do more of those!"
> > from http://www.python.org/dev/peps/pep-0020/
> > Absolutely correct. The namespace pollution is exactly why we encourage converts to move over from the pylab mode to separating out the numpy and pyplot namespaces. There are very subtle issues that arise when doing "from pylab import *" such as overriding the built-in "any" and "all". The only real advantage of the pylab mode over separating out numpy and pyplot is conciseness, which many matlab users expect at first.
> It unfortunately also comes with the convenience of using the "ipython --pylab" mode -
> does anyone know how to turn the "import *" part of, or how to create a similar working
> environment with ipython that does keep namespaces clean?
> There's a config flag that you can add to your ipython profile:
> c.TerminalIPythonApp.pylab_import_all = False
> For example, my profile is in ~/.ipython/profile_default/ipython_config.py
thanks, that was exactly what I was looking for - together with
c.TerminalIPythonApp.exec_lines = ['import sys',
'import numpy as np',
'import matplotlib as mpl',
'import matplotlib.pyplot as plt']
etc. to have the shortcuts.
More information about the NumPy-Discussion