On Wed, Dec 23, 2009 at 02:37:22PM -0800, William Stein wrote: > On Wed, Dec 23, 2009 at 2:31 PM, Nicolas M. Thiery > <nicolas.thi...@u-psud.fr> wrote: > > On Wed, Dec 23, 2009 at 02:01:22PM -0800, William Stein wrote: > >> > I stumbled recently into a nifty feature of the IPython interpreter > >> > allowing for easy manipulations of the global namespace of the > >> > interpreter, at the python level. Thanks to it, one can now do: > >> > > >> > sage: S = SymmetricFunctions(ZZ) > >> > sage: S.import_shorthands() > >> > sage: s[1] + e[2] * p[1,1] + 2*h[3] + m[2,1] > >> > s[1] - 2*s[1, 1, 1] + s[1, 1, 1, 1] + s[2, 1] + 2*s[2, 1, 1] + s[2, > >> > 2] + 2*s[3] + s[3, 1] > >> > sage: s > >> > Symmetric Function Algebra over Integer Ring, Schur symmetric > >> > functions as basis > >> > sage: e > >> > Symmetric Function Algebra over Integer Ring, Elementary symmetric > >> > functions as basis > >> > ... > >> > >> What happens in the notebook (which in no way uses IPython)? Does it > >> at least fail gracefully? > > > > Good point. I am using that seldom the notebook that I did not even > > think about it :-) Let me try ... Ok, as I expected, it's not that graceful: > > > > Traceback (click to the left for traceback) > > ... > > AttributeError: 'NoneType' object has no attribute 'to_user_ns' > > > > Is there an easy way to manipulate the global namespace for the > > notebook? For IPython, I am using: > > No, not exactly. The notebook is just pure Python (right now). > > That said, from *Cython* you can get at the true global namespace by > using the command globals(). See > > sage/sage/ext/interactive_constructors_c.pyx > > for code that does this sort of thing, which works uniformly in both > IPython, pure python, and the notebook.
Yeah, I had seen this. I was specifically happy to have found a non-cython way to do it. But uniformity has its value. I guess I'll make a very small Python wrapper around the Cython globals call, and then have import_shorthands use it. sage: sage.misc.misc.inject_variables(dict('a':1, 'b':3)) sage: a 1 sage: b 3 Any better suggestion for the location/name of this function? import_variables? Or should we use S.inject_shorthands() above? Cheers, Nicolas -- Nicolas M. Thiéry "Isil" <nthi...@users.sf.net> http://Nicolas.Thiery.name/ -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org