IPython developers to absorb the basic concept of the standard interpreter, on the basis of a lot of improvements, creating an amazing tool. On its home page says so:. "This is an enhanced interactive Python shell" has tab completion, object introspection, strong history mechanism, embedded in the source code editor, integrated Python debugger,% run mechanism , macros, create multiple environments and the ability to call the system shell.
1) The biggest difference IPython and standard Python is that each row Ipython command prompt will be numbered.
Compare two examples, the output variable values seem the same, in fact there are still differences. print statement informal (unofficial) string expression, and simple variable name (bare variable name) uses the formal (official) string expression. In dealing with the custom class instead of built-in classes, this difference will be reflected very clearly.
In : class DoubleRep (object):
....: Def __str __ (self):
....: Return 'Hi, I'm a __str__'
....: Def __repr __ (self):
....: Return 'Hi, I'm a __repr__'
In : dr = DoubleRep ()
In : print dr
Hi, I'm a __str__
In : dr
Out : Hi, I'm a __repr__
2) tab completion
As an example, we first introduced the sys module, then re-enter sys. (Note that there is a point), then press the tab key, IPython will list all the methods and properties under the sys module.
Continuing the above example, we enter sys? Re-enter, it will show the docstring and related information sys module. Many times this is a very handy feature.
3) history mechanism
hist can quickly see that the history of the input.
hist -n can quickly view and remove the history of the number, so you can easily copy the code into a text editor.
A simpler method is to add slice edit Python list (slice) syntax:
4 edit: 7% to export the first sentence of 4,5,6,7 code to the editor
4) breakpoint debugging: If your program is started from the command line, ie input python foo.py (most Python programs are) in the command line, you can also use IPython anywhere in your program be breakpoint debugging.
Anywhere in your application, add the following statement:
from IPython.Shell import IPShellEmbed
IPShellEmbed () ()
Note: IPython recently released version 0.11, all changes are very large, API has also been redesigned. If you are using two lines corresponding to 0.11 so it is this:
from IPython import embed
And then run your program as usual, you will find that when the program is run to place the insert statement, it will go to the next IPython environment. You can try to run some commands, you will find at the moment IPython environment is, at that point in the program. You can step through the various variables in the current state, call the various functions, the output value you are interested in to help debug. Then you can exit IPython as usual, then the program will continue to run down, naturally you execute the statement at the time IPython also affect the next program run.
This method is here (http://lukeplant.me.uk/blog/posts/exploratory-programming-with-ipython/) to see. Imagine doing so as to make high-speed operation of the program paused, then you run the program to check and modify, and then let him continue to run down. To give an example, such as writing web bot, you get back a page in each post you have to look at its contents, and then try to address how to deal with him to get to the next page. Using this technique, you can let the program after retrieving the page break, and then experiment where various treatment methods, to find the right way to handle write back to your code, then the next step. This workflow is only dynamic language like Python that can be done.