IPython - Importing Python Shell Code


Advertisements

IPython can read from standard Python console with default >>> prompt and another IPython session. The following screenshot shows a for loop written in standard Python shell −

Standard Python Shell Loop

Copy the code (along with Python prompt) and paste the same in IPython input cell. IPython intelligently filters out the input prompts (>>> and ...) or IPython ones (In [N]: and ...:)

IPython Input Cell

Similarly, code from one IPython session can be pasted in another. The first screenshot given below shows definition of SayHello() function in one IPython window −

IPython window

Now, let us select the code and paste in another IPython shell and call SayHello() function.

IPython shell Cmd
Advertisements