[SciPy-dev] Moving random.py

Fernando Perez Fernando.Perez at colorado.edu
Fri Dec 16 19:02:47 CST 2005

Pearu Peterson wrote:

> I just realized that scipy could do similar to Maple when importing 
> packages that provide global symbols.
> For example, when executing
>    import scipy.fftpack
> in interactive shell then code like (untested, unoptimized)
> from scipy.distutils.misc_util import get_frame
> if get_frame(1).f_locals['__name__']=='__main__':
>      # expose fft to interactive shell
>      exec 'fft = scipy.fftpack.fft' in get_frame(1).f_locals,get_frame(1).f_globals
> at the end of fftpack/__init__.py would expose fft function to interactive 
> shell (Maple would show also a warning on changing global namespace if I 
> recall correctly).

-1 on this: for one thing, the caller's interactive namespace is not 
necessarily one frame above in the stack, so this is fairly brittle.  It 
wouldn't work in ipython, for example, as the user's locals/globals are 
internally managed dicts and not the frame object's f_locals/f_globals.  It 
would also fail on shells that have more levels of indirection, because 
__name__ != '__main__' until you actually reach the command-line script that 
invoked the shell.

I also dislike this 'automatic promotion' from a simple import statement, too 
much implicit behavior for my taste.  I think that the import_all() solution, 
along with Gary's idea, provide a cleaner solution to these issues, which is 
also (a big plus IMHO) actually robust.



More information about the Scipy-dev mailing list