Data analysis using Python (iii) Improve development efficiency with IPython

Source: Internet
Author: User
Tags clear screen

I. Introduction of IPython
IPython is an interactive Python interpreter, and it's more efficient. It differs from most traditional working modes (edit-and-compile-run),The working mode it uses is: Execute-and explore, and most of the code related to data analysis contains exploratory operations (such as trial and error methods and iterative methods), so IPython can greatly improve coding efficiency.
IPython now, it's not just a reinforced Python shell,It integrates the GUI console, which allows you to draw directly; it also has a Web-based interactive notebook and a lightweight, fast parallel computing engine.

Second, write the code
enter Ipython in Terminal to start Ipython. If you need to use the Matplotlib library, you need to mark the integration Matplotlib package when you start, the start command changes to: Ipython--pylab
1. Learn to use the Tab key
When entering the code, if this is a previously entered content (such as the previously defined variable), you only need toafter entering the first few letters, press the TAB key to complete the completion automatically. IPython has this feature as a major improvement to the standard Python shell, which is already very common in other languages of the IDE.
Not only can auto-complement variables, objects, and so on, like typing commands in the Terminal Tab key can also automatically complete the file path.
2. Up and DOWN ARROW keys, enter history command quickly
When a command or code needs to be entered repeatedly, you do not have to manually knock it all the time, you only need to use the UP ARROW key to automatically complete the previous command, and then continue to press the arrow key is the upper command. If a command needs to be pressed many times on the arrow keys to find it, just enter the first few letters of that command and then press the arrow key to filter only the commands that match the first few letters.
3. Execute a. py file
If you want to execute an external. py file, use the%run command, for example:
4. View common information about the relevant code
When you need to see a variable or object-related generic information, add a question mark after the variable and press the ENTER key. For example:
If a function contains docstring, add a question mark (?) after the function name to view the relevant docstring content, or add two question marks (??) after the function name. ), you can display the source code associated with the function, for example:
5. Shortcut keys related to the encoding process
    • ctrl+f cursor moves forward 1 characters
    • ctrl+b The cursor moves back 1 characters
    • CTRL + A cursor moves to the beginning
    • ctrl+e cursor moves to end of line
    • Ctrl+u all content before the line cursor is deleted
    • ctrl+k Delete all content after this line cursor
    • ctrl+l Clear Screen (Mac under Cmd+k can also)

third, debug code
1. Start the debugger after the code has an exception
After the code has an exception, entering the%debug command launches the debugger and automatically jumps to the "location of the incident":
Enter the Q command to exit the debugger.
2. Single Step execution
Use the%run command with the-D option to pre-open the debugger, enter s step into the function call, enter the n command to execute to the next line of code, enter the exclamation mark (!) and then enter the variable name to see the value of the variable. For example:
This command adds an option to specify a line number (-B) to set a breakpoint when the debugger is started, for example:
The next essay is: Data analysis using Python (iv) NumPy base-ndarray arrays and vector Computing, interested friends Welcome to pay attention to this blog, but also welcome you to add comments to discuss.

Data analysis using Python (iii) Improve development efficiency with IPython

Related Article

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.