3 Python shell for SymPy. Executes the commands in the "init_code" variable
4 before giving you a shell.
7 -c : permits to specify a python interactive interpreter, currently only
8 python or ipython. Example usage:
10 default is set to ipython
12 -h : prints this help message
14 --version: prints version number
19 x, y, z = symbols('xyz')
20 k, m, n = symbols('kmn', integer=True)
27 from sympy
import __version__
as sympy_version
28 python_version
= "%d.%d.%d" % tuple(sys
.version_info
[:3])
31 """Puts ">>> " in front of each line."""
33 for l
in s
.split("\n"):
39 "Python %s console for SymPy %s. These commands were executed:\n%s" % \
40 (python_version
, sympy_version
, indent(init_code
))
42 def run_ipython_interpreter():
44 from IPython
.Shell
import IPShellEmbed
46 #is the -nopprint necessary?
49 ipshell
= IPShellEmbed(args
)
50 api
= ipshell
.IP
.getapi()
52 api
.ex('__IP.compile("from __future__ import division", "<input>", "single") in __IP.user_ns')
54 ### create some magic commands
56 #def pretty_print(self, arg):
57 # self.api.ex("print str((%s).__pretty__())" % arg)
59 #api.expose_magic("pprint", pretty_print)
61 # Now start an embedded ipython.
63 sys
.exit("Exiting ...")
65 def run_python_interpreter():
67 Couldn't locate IPython. Having IPython installed is greatly recommended. See
68 http://ipython.scipy.org for more details. If you use Debian/Ubuntu, just
69 install the "ipython" package and start isympy again.\n"""
77 class HistoryConsole(code
.InteractiveConsole
):
78 def __init__(self
, locals=None, filename
="<console>",
79 histfile
=os
.path
.expanduser("~/.sympy-history")):
80 code
.InteractiveConsole
.__init
__(self
)
81 self
.init_history(histfile
)
83 def init_history(self
, histfile
):
84 readline
.parse_and_bind("tab: complete")
85 if hasattr(readline
, "read_history_file"):
87 readline
.read_history_file(histfile
)
90 atexit
.register(self
.save_history
, histfile
)
92 def save_history(self
, histfile
):
93 readline
.write_history_file(histfile
)
97 sh
.interact(welcome_msg
)
98 sys
.exit("Exiting ...")
101 from optparse
import OptionParser
104 from sympy
import __version__
as sympy_version
105 parser
= OptionParser("usage: isympy [options]", version
=sympy_version
)
106 parser
.add_option("-c", "--console", dest
="console",
107 help="specify a python interactive interpreter, python or ipython")
108 (options
, args
) = parser
.parse_args()
110 if options
.console
== "python":
111 run_python_interpreter()
112 elif options
.console
== "ipython":
113 run_ipython_interpreter()
116 run_ipython_interpreter()
119 run_python_interpreter()
121 if __name__
== "__main__":