Uncategorized

How to embed an IPython shell in your application

If you by any chance would like to use the excellent python shell IPython as an embed shell on an application or virtual terminal, you can instantiate it using the IPShellEmbed class provided by IPython. Let’s say that your environment doesn’t like IPython default color scheme and you need to start it without colors (same as doing ipython -colors NoColor). You can use an embed shell in your code the following way:


import IPython

embedshell = IPython.Shell.IPShellEmbed(argv=["-colors", "NoColor"])

embedshell()

argv are the arguments you would normally pass to the main ipython script.

I hope that was useful 🙂

Advertisements

One thought on “How to embed an IPython shell in your application

  1. This has apparently changed in new versions of iPython. Now you just use: from IPython import embed and then call the embed() function (no instantiation necessary)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s