English 中文(简体)
Importing Python Shell Code
  • 时间:2024-11-03

IPython - Importing Python Shell Code


Previous Page Next Page  

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 intelpgently 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