# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1197442114 28800
# Node ID f5b669b3e3ec0c4fe6dc4d88fa90814b4d9e1968
# Parent  e8a8784711064fd3ef1ab08f3a94a53242f487b8
Trac #1423 -- bug/issue in python.eval from sage (fixed)  with help from Marshall Hampton and Clarita Lefthand

diff -r e8a878471106 -r f5b669b3e3ec sage/misc/python.py
--- a/sage/misc/python.py	Tue Dec 11 16:25:49 2007 -0800
+++ b/sage/misc/python.py	Tue Dec 11 22:48:34 2007 -0800
@@ -3,6 +3,29 @@ class Python:
     Allows for evaluating a chunk of code without any preparsing.
     """
     def eval(self, x, globals={}, locals={}):
+        """
+        Evaluate x with given globals (locals is ignored).  This is
+        specifically meant for evaluating code blocks with
+        \code{%python} in the notebook.
+
+        EXAMPLES:
+            sage: from sage.misc.python import Python
+            sage: python = Python()
+            sage: python.eval('2+2')
+            4
+            ''
+            sage: python.eval('a=5\nb=7\na+b')
+            12
+            ''        
+        
+        The locals variable is ignored -- it is there only for
+        completeness.  It is ignored since otherwise the following
+        won't work:
+            sage: python.eval("def foo():\n return 'foo'\nprint foo()\ndef mumble():\n print 'mumble',foo()\nmumble()")
+            foo
+            mumble foo
+            ''
+        """
         x = x.strip()
         y = x.split('\n')
         if len(y) == 0:
@@ -14,11 +37,11 @@ class Python:
         except SyntaxError:
             s += '\n' + t
             z = None
-        #else:
-        #    s += '\n' + t
-        eval(compile(s, '', 'exec'), globals, locals)
+
+        eval(compile(s, '', 'exec'), globals)
+        
         if not z is None:
-            eval(z, globals, locals)
+            eval(z, globals)
         return ''
 
 python = Python()
