Full Pycharm Tutorial (--pycharm) template application of the editor function

Source: Internet
Author: User

Pycharm comes with a lot of flexible templates, but there's only one template for Python itself. Here we will detail how to create a template for the Python class and use it.

We will not dwell on Python programming and the use of basic templates here. For information about the type, abbreviation, variable name, and storage of the template, see Live Templates, how to use the template, see Creating Code constructs by Live Templates.

2. Preparatory work

Pycharm version 2.7 or higher, please install them yourself.

3, the template of the private custom-made

4. Create a root template

Open the Settings dialog box (click the toolbar's Settings button, or press the Ctrl+alt+s shortcut key), under IDE settings settings, click Live Templates:

Click the green plus sign to wait for the miracle.

First, notice that a new grouping appears under user.

Second, a root template named <abbreviation> appears after the user group is selected

Finally, the interface has an abbreviation, description, template content and other input window.

5. Specify the abbreviation and context of the template

The first step is to enter the template abbreviation templates abbreviation, which is defined as class. Then enter the description description description (optional) To specify the context of the template application (Python is selected here):

The top expansion value selects the default tap.

6. Define template text

Enter the following code in the template text field:

Where you use the $ tag to enclose the portion of the template variable that is labeled Variables,pycharm to mark it red for easy identification:

These template variables are currently empty, and we define them next.

4. Edit Template variables

Click the Edit variables button:

The current list of template variables is displayed in the Edit Templates variables dialog box:

For the variable $object$, we give the default value (object) and click the OK button:

The variables shown in the list above do not contain $END $, visible pyhcarm do not want us to change them. This is because $END $ has already been predefined and is therefore not editable. It is used to indicate the default position of the input cursor after the template is expanded, so that we can perfect the code corresponding to the template. Our cursor here will be placed after the class declaration by default.

5. Save the custom template

Very simple, click the OK button in the Settings window.

6. Using custom templates

First, create a Python file, named Mypythonfile, here:

Edit this new Python file. Next we create a class declaration in it. Enter the template abbreviation class and you'll find that our custom templates are already in the cue list, yes, the one we just defined:

Press the TAP key to select the item.

As expected, the abbreviated name expands successfully into a basic Python class. The red underline marks the position you want to enter next, and when you enter the class name (corresponding to the template variable Class), it is inserted into the current red wavy line position:

Note that the template variable class here has been applied twice: in the declaration statements and constructors of the class. In the constructor, Pycharm is automatically populated (populated with self).

Enter the class name, carriage return, red wavy line to the next line, enter the corresponding content, and finally return:

Finally, the cursor is positioned at the end of the class.

For more custom template information see Creating Code constructs by Live Templates.

Full Pycharm Tutorial (--pycharm) template application 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.