sympy/sympy — pull request #643 by mattpap (2011-10-10 02:18:19+00:00)
Title: Automatically construct missing symbols in isympy

By default, if a symbol was not defined before code execution, NameError
exception is raised:

```
$ bin/isympy -q
IPython console for SymPy 0.7.1-git (Python 2.6.6-64-bit) (ground types: gmpy)

In [1]: 'a' in globals()
Out[1]: False

In [2]: integrate(a*x, x)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/home/mateusz/repo/git/sympy/ in ()
----> 1 integrate(a*x, x)

NameError: name 'a' is not defined

In [3]: 'a' in globals()
Out[3]: False

In [4]:
Do you really want to exit ([y]/n)?
Exiting ...
```

However, in IPython (>= 0.11) if -a or --auto command line option is
specified, all NameError exceptions that are raised in the interpreter's
stack frame are ignored and appropriate symbols constructed and injected
into the global namespace, and code rerun:

```
$ bin/isympy -q -a
IPython console for SymPy 0.7.1-git (Python 2.6.6-64-bit) (ground types: gmpy)

In [1]: 'a' in globals()
Out[1]: False

In [2]: integrate(a*x, x)
Out[2]:
2
a⋅x
────
2

In [3]: 'a' in globals()
Out[3]: True
```

Note that any other NameError exceptions are handled by standard
IPython traceback printing procedures:

```
In [4]: def f(): return b

In [5]: f()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/home/mateusz/repo/git/sympy/ in ()
----> 1 f()

/home/mateusz/repo/git/sympy/ in f()
----> 1 def f(): return b

NameError: global name 'b' is not defined
```