Python uses IPython to improve development efficiency.
I. Introduction to IPython
IPython is an interactive Python interpreter and is more efficient.
Unlike most traditional working modes (edit-> compile-> RUN), it adopts the following working modes: Execution-> exploration, while most of the generation related to data analysis
Code contains exploratory operations (such as trial and iteration methods), so IPython can greatly improve the coding efficiency.
Since the development of IPython, it is not just an enhanced version of Python shell, it integrates the GUI console, which allows you to directly perform drawing operations; it also has a Web-based notebook and a lightweight fast parallel computing engine.
2. write code
Enter ipython in Terminal to start IPython.
If you need to use the Matplotlib library, you need to mark the integration of the Matplotlib package at startup, then the startup command is changed to: ipython -- pylab
1. Learn to use the Tab key
When you enter the code, if this is a previously entered content (such as the variable defined earlier ), you only need to press the Tab key after entering the first few letters to automatically complete.
IPython has this function as a major improvement to the standard Python shell, which is already very common in IDE in other languages.
It can not only automatically complete variables and objects, but also automatically complete the file path as if you typed the command in Terminal.
2. Press the up and down arrow keys to quickly enter History commands.
When a command or code needs to be repeatedly input, you do not have to manually repeat it each time. You only need to use the up arrow to automatically complete the previous command; then press the arrow key to run the preceding command.
If you need to press the arrow key multiple times to find a command, you only need to enter the first few letters of the 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 view the common information related to a variable or object, 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 (?) You can also view the relevant docstring content;
If you add two question marks (?) after the function name (??), The Source Code related to the function is displayed, for example:
5. Related shortcut keys during encoding
Ctrl + F move the cursor forward by 1 Character
Ctrl + B move the cursor one character behind
Ctrl + A move the cursor to the beginning of the line
Ctrl + E move the cursor to the end of the row
Ctrl + U delete all content before this row cursor
Ctrl + K delete all content after this row cursor
Ctrl + L clear screen (Cmd + K under Mac)
Iii. Code debugging
1. Start the debugger when an exception occurs in the code
After an exception occurs in the code, enter the % debug command to start the debugger and automatically jump to the "event location ":
Enter the q command to exit the debugger.
2. One-step execution
You can use the % run command with the-d option to open the debugger in advance, enter the s step into the function call, enter the n command to execute the next line of code, and enter the exclamation point (!) Enter the variable name to view the value of the variable. For example:
If you add another option (-B) for the specified line number, you can set a breakpoint when starting the debugger. For example:
Summary
The above is all about how Python uses IPython to improve development efficiency. I hope this article will help you learn how to use python.