[IPython-dev] confirm_exit issue with scipy profile...

Hans Meine hans_meine@gmx....
Tue Aug 21 04:17:47 CDT 2007


Am Dienstag, 21. August 2007 09:17:24 schrieben Sie:
> Yeah, the benefits of the new config files mostly become apparent with
> less trivial cases.
I noticed that.  I just wanted to point this out (again), so maybe the trivial 
cases can get better support.

> Of course you could add 
>
> def import_all(m): ip.ex('from %s import *' % m)
>
> to the beginning of the file yourself.

That's a good idea.  But wouldn't it be nice to provide this function in 
ipython itself?  Maybe extended like this:

def import_all(*modules):
  for m in modules:
    ip.ex('from %s import *' % m)

or even:

def import_all(modules):
  for m in modules.split():
    ip.ex('from %s import *' % m)

The latter would allow writing e.g.

import_all("math os numpy")

Also, one might include "from IPython import ipapi" in the namespace.

> > And -- please point out if I missed something -- although I would
> > occasionally like to run arbitrary python code *in the user namespace*,
> > the new config files need me to wrap it in string quotes for ip.ex(), no?
> > (Losing syntax highlighting, automatic indentation etc. in my editor..)
>
> Of course you can still put stuff in modules, and import them with ip.ex.
>
> There is really nothing you "need" to do with the new style, apart
> from verifying it's legal Python... and that's a good thing.

Yes, it's a really good thing, but not every ipython user wants to write a 
sophisticated config file (I know a lot of people who do not even bother 
creating their own profiles, but simply execfile() their setup scripts).  It 
would simplify matters if there was an additional config API for the simple 
things.

Reciting you from above:
> Of course you can still put stuff in modules, and import them with ip.ex.
I thought about that, yes.  But I wonder if it wouldn't be better to accompany 
each ip_profile_foo with an ipy_profile_foo_userspace which is automatically 
loaded?  Or - even better - add a special entrypoint in ipy_profile_foo.py 
for code automatically run in userspace.  Currently, the code is simply 
import'ed, right?  Hmm, I see no nice (and backwards-compatible), 
non-complicated way of differentiating between the two namespaces then. :-(

Is .ipython in sys.path?  Apparently not.  I tried moving my code into an 
ipy_handy_utils.py and adding ip.ex("from ipy_handy_utils import *") to 
ipy_user_conf.py, but I am getting:
> WARNING: Could not import user config!
>  ('/home/meine/.ipython/ipy_user_conf.py' does not exist? Please run
> '%upgrade')
Seems to be a caught exception - obviously all ImportErrors are caught.  
AFAICS, this should be changed to check whether the failed import actually 
was ipy_user_conf itself.  I cannot check right now, because the 
ipython.scipy.org seems to be down right now.

Nice greetings,
  Hans


More information about the IPython-dev mailing list