Most complete Pycharm tutorial (--pycharm) code automatic generation mechanism of the editor function

Source: Internet
Author: User

  

Most complete Pycharm Tutorials (1)--Custom Skins

Most full Pycharm Tutorials (2)-code style

Most full Pycharm Tutorials (3)-code debugging, running

Most complete Pycharm Tutorials (4)--related configuration for Python interpreter

Most full Pycharm Tutorials (5)--python shortcut key Related settings

Most full Pycharm Tutorials (6)--using Pycharm as a VIM editor

Most full Pycharm Tutorials (7)--Configuration of VM VMs

Most complete Pycharm tutorials (8) creation and management of--django engineering

Most complete Pycharm Tutorials (9)--Create and run a basic Python test program

Most complete Pycharm tutorial (Ten)--pycharm Debugger General Chapter

Most complete Pycharm tutorial (one)--pycharm Debugger Breakpoint Chapter

Full Pycharm Tutorial (--pycharm) Java Script debugging for the debugger

Most complete Pycharm tutorial (--pycharm) deployment

The most complete pycharm tutorial (+)--pycharm Editor features General Chapter

1. Theme

As already mentioned, Pycharm has powerful spelling hints, including basic and smart type, and in addition Pycharm can automatically generate some structured code, insert pairs of curly braces and quotes, and then we'll explore.

2. Auto Indent

Type the class declaration, and then enter:

The Pycharm cursor automatically reserves the indentation, where you can begin entering function declarations:

The mechanism for automatic indentation is now started. Here the function declaration (and all nested operations) is indented by default from the left by 4 space positions. The indentation rules here involve Python's relatively fixed code style standards, which are tailored to your team (that is, a company needs to follow a unified standard), and Pycharm will help us maintain the code style according to the standard when the standard is specified. Next, we introduce how pycharm specifically implements this function. Also take this simple code example, open the Settings dialog box, expand the Code Style node, open the Python page (ctrl+alt+s→Project settings→code style→python):

As you can see, the indentation size specified here is 4 spaces, and Pycharm follows this rule to automate the generation of code and format check reformatting. Of course we change the indentation rules (just as you would modify other code rules). Suppose you want to indent the number of 5 spaces, that is, all the new code generated is 5 spaces in relation to the upper-level code. Browse the Smart keys page for more details.

However, the Pycharm preset code style framework is immutable, Pycharm will automatically copy and copy copies for us to modify before making a private subscription:

This new configuration framework is saved in your user directory, and if necessary, you can share it with other teammates to make it easy to unify the style of the entire team code. For more information about code styling, see Project and IDE Settings.

3. Automatic grammar completion

When you enter a parenthesis (Pycharm will try to fill the other half), Pycharm will complete the system parameter self. After the carriage return, the cursor moves to the next input position (based on the current indentation rule), where you enter the information you want to print, enter a parenthesis, Pycharm automatically complements the other half of the parentheses, and the cursor inside the brackets for us to enter the information to be printed:

Next we'll test a more complex scenario--edit a Django template. For the syntax of a very complex Django template, the automatic grammar completion function is critical. OK, start typing a django tag

Once you type in a curly brace, the pycharm automatically complements the other one:

And the cursor will stop at two%, so we can enter the code:

Similarly, the {{flag pycharm also automatically complements the other half.

The relevant settings for the automatic grammar completion feature are located in the Smart Keys page of the editor settings:ctrl+alt+s→IDE settings→editor→smart keys:

For example, if you want Pycharm to be able to automatically complete parentheses, brackets, and so on, you need to check the insert pair bracket checkbox; To automatically complete the quotes, you need to tick the insert pair quote check box. For Django templates, there is a special check box Auto-insert closing}} and%} in Django templates to choose from.

  

Most complete Pycharm tutorial (--pycharm) code automatic generation mechanism of the editor function

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.