Differences between IPython and Python

Source: Internet
Author: User

Differences between IPython and Python

IPython developers have absorbed the basic concepts of the standard interpreter and made a lot of improvements on this basis to create an amazing tool. On its home page, it says, "This is an enhanced interactive Python shell ." With tab completion, object introspection, powerful history mechanism, embedded source code editing, integrated Python debugger, % run mechanism, Macro, ability to create multiple environments and call system shell.

1) The biggest difference between IPython and standard Python is that Ipython numbers each line of the command prompt. For example:

Compared with the two examples, the output variable values seem to be the same, but there are still differences. The print statement uses an informal (unofficial) string expression, while the simple variable name (bare variable name) uses a formal (official) string expression. This difference is evident when processing custom classes instead of built-in classes.
In [10]: class DoubleRep (object ):
...: Def _ str _ (self ):
...: Return 'Hi, I'm a _ str __'
...: Def _ repr _ (self ):
...: Return 'Hi, I'm a _ repr __'
....:
....:
In [11]: dr = DoubleRep ()
In [12]: print dr
Hi, I'm a _ str __
In [13]: dr
Out [13]: Hi, I'm a _ repr __


2) tab completion
As an example, we first introduce the sys module, and then enter sys. (Note that there is a point). Press the tab key, IPython will list the methods and attributes of all sys modules.

Next, in the example above, we enter sys? Press enter to display the docstring and related information of the sys module. This is also a convenient feature in many cases.

3) Historical Mechanism
Hist allows you to quickly view the input history.
Hist-n allows you to quickly view and remove sequence numbers from history records, so that you can easily copy the code to a text editor.
A simpler method is to add the slice syntax of the edit and Python list:
Edit 4: 7% Export Code 4, 5, 6, and 7 to the editor


4) breakpoint debugging: If your program is executed by the command line, enter python foo. py (most Python programs), you can also use IPython to perform breakpoint debugging anywhere in your program.
Add the following statement anywhere in your program:
From IPython. Shell import IPShellEmbed
IPShellEmbed ([]) ()
Note: Recently, IPython version 0.11 has been released, with great changes in all aspects and the API has been re-designed. If you use 0.11, the above two rows correspond to the following:
From IPython import embed
Embed ()
Run your program as usual. You will find that when the program runs to the place where the statement is inserted, it will be transferred to the IPython environment. You can try running some commands to find that the IPython environment is at the position of the program at the moment. You can view various variables in the current state one by one, call various functions, and output values of interest to help debugging. Then you can exit IPython as usual, and the program will continue to run. Naturally, the statements you run under IPython will also affect the subsequent running of the program.
This method is seen here (http://lukeplant.me.uk/blog/posts/exploratory-programming-with-ipython. Imagine that this is like suspending a high-speed program. You can check and modify the running program and then let it continue running. Here is an example. For example, if you compile a Web page bot, you have to check its content every time you retrieve a page, and then try to get the address of the next page. With this technique, you can interrupt the program after retrieving the page, experiment with various processing methods, write the correct processing method back to your code, and then proceed to the next step. This kind of workflow can only be done in a dynamic language like Python.

In CentOS 6.4, how does IPython start the Qt console and NoteBook?

Install IPython in CentOS 5

Install IPython 0.11 on CentOS and RHEL.

CentOS6.5 install Python2.7.8 and IPython

For details about IPython, click here
IPython: click here

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.