~ipython-dev/ipython/0.10.1

« back to all changes in this revision

Viewing changes to doc/examples/example-embed-short.py

  • Committer: Fernando Perez
  • Date: 2008-06-02 01:26:30 UTC
  • mfrom: (0.1.130 ipython-local)
  • Revision ID: fernando.perez@berkeley.edu-20080602012630-m14vezrhydzvahf8
Merge in all development done in bzr since February 16 2008.

At that time, a clean bzr branch was started from the SVN tree, but
without SVN history.  That SVN history has now been used as the basis
of this branch, and the development done on the history-less BZR
branch has been added and is the content of this merge.  

This branch will be the new official main line of development in
Launchpad (equivalent to the old SVN trunk).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Quick code snippets for embedding IPython into other programs.
2
 
 
3
 
See example-embed.py for full details, this file has the bare minimum code for
4
 
cut and paste use once you understand how to use the system."""
5
 
 
6
 
#---------------------------------------------------------------------------
7
 
# This code loads IPython but modifies a few things if it detects it's running
8
 
# embedded in another IPython session (helps avoid confusion)
9
 
 
10
 
try:
11
 
    __IPYTHON__
12
 
except NameError:
13
 
    argv = ['']
14
 
    banner = exit_msg = ''
15
 
else:
16
 
    # Command-line options for IPython (a list like sys.argv)
17
 
    argv = ['-pi1','In <\\#>:','-pi2','   .\\D.:','-po','Out<\\#>:']
18
 
    banner = '*** Nested interpreter ***'
19
 
    exit_msg = '*** Back in main IPython ***'
20
 
 
21
 
# First import the embeddable shell class
22
 
from IPython.Shell import IPShellEmbed
23
 
# Now create the IPython shell instance. Put ipshell() anywhere in your code
24
 
# where you want it to open.
25
 
ipshell = IPShellEmbed(argv,banner=banner,exit_msg=exit_msg)
26
 
                            
27
 
#---------------------------------------------------------------------------
28
 
# This code will load an embeddable IPython shell always with no changes for
29
 
# nested embededings.
30
 
 
31
 
from IPython.Shell import IPShellEmbed
32
 
ipshell = IPShellEmbed()
33
 
# Now ipshell() will open IPython anywhere in the code.
34
 
 
35
 
#---------------------------------------------------------------------------
36
 
# This code loads an embeddable shell only if NOT running inside
37
 
# IPython. Inside IPython, the embeddable shell variable ipshell is just a
38
 
# dummy function.
39
 
 
40
 
try:
41
 
    __IPYTHON__
42
 
except NameError:
43
 
    from IPython.Shell import IPShellEmbed
44
 
    ipshell = IPShellEmbed()
45
 
    # Now ipshell() will open IPython anywhere in the code
46
 
else:
47
 
    # Define a dummy ipshell() so the same code doesn't crash inside an
48
 
    # interactive IPython
49
 
    def ipshell(): pass
50
 
 
51
 
#******************* End of file <example-embed-short.py> ********************