Show More
@@ -0,0 +1,32 b'' | |||
|
1 | """ An example of one way to embed IPython in your own application | |
|
2 | ||
|
3 | This basically means starting up IPython with some of your programs objects visible in the IPython | |
|
4 | user namespace. | |
|
5 | ||
|
6 | """ | |
|
7 | ||
|
8 | import sys | |
|
9 | sys.path.append('..') | |
|
10 | ||
|
11 | import IPython.ipapi | |
|
12 | ||
|
13 | my_ns = dict(a=10) | |
|
14 | ||
|
15 | ses = IPython.ipapi.make_session(my_ns) | |
|
16 | ||
|
17 | # Now get the ipapi instance, to be stored somewhere in your program for manipulation of the running | |
|
18 | # IPython session. See http://ipython.scipy.org/moin/IpythonExtensionApi | |
|
19 | ||
|
20 | ip = ses.IP.getapi() | |
|
21 | ||
|
22 | # let's play with the ipapi a bit, creating a magic function for a soon-to-be-started IPython | |
|
23 | def mymagic_f(self,s): | |
|
24 | print "mymagic says",s | |
|
25 | ||
|
26 | ip.expose_magic("mymagic",mymagic_f) | |
|
27 | ||
|
28 | # And finally, start the IPython interaction! This will block until you say Exit. | |
|
29 | ||
|
30 | ses.mainloop() | |
|
31 | ||
|
32 | print "IPython session finished! namespace content:",my_ns |
General Comments 0
You need to be logged in to leave comments.
Login now