Vscode the editor to write Python code

Source: Internet
Author: User

In the course of learning python, we have not found a third-party editor that compares the hand, with the most Python-brought editor. As I used to use the universe's first IDE (Visual Studio), when Visual Studio code appeared, the mood was a little excited. From my experience, it can be said that Vscode used to write Python is really suitable, you will experience a silky programming experience and the possibility of unlimited expansion. And, if your project is multi-lingual, such as web development, you don't have to open multiple editors and other tools, because all of this can be done in Vscode.

Build the Environment

Search for extended python in Vscode, this is the shipment:

After installation, reload. I have already installed it, so the Disable, uninstall button is displayed.

You can happily play with Python below. Isn't it super convenient?

Basic operations

Start your first Python code in Vscode, and the Python plugin's pylint feature will automatically prompt you, auto-complete, and error-Prompt as you type.

We need to remind you Pythoner, Vscode includes vs, tab is 4 spaces by default.

Several commonly used shortcut keys, estimated that the vser can be painless conversion:

    • The first is the F1/CTRL+SHIT+P Universal key, who knows with whom
    • Ctrl+p: File Switching
    • CTRL + SPACE: Auto prompt
    • f12/ctrl+ left button: Jump to Definition
    • SHIFT+F12: Preview Definition
    • CTRL+G: Jump Switch number
    • ctrl+/: Comment Toggle
    • Alt+↑↓: Move up and down the entire line
    • Ctrl+↑↓: Editor vertical scroll bar moves up or down, cursor does not move
    • Ctrl+backspace/delete: integer word/continuous blank deletion
    • ctrl+→←: Cursor Whole word movement
    • Ctrl+f find/ctrl+shift+f in the file to find, this is generic, like not to say AH.

Preview Definition diagram:

Debugging operations

F5 Debug runs anytime, anywhere. Note that the Vscode default after debugging, will stop in the first sentence, such as.

Debugging shortcuts are basically the same as vs.

    • F5: Debug/Continue,
    • F10: One-step skip,
    • F11: One Step into the
    • SHIFT+F11: Jump out.
    • F9: Toggle Breakpoint

The Left debug window shows the top-to-bottom debug mode, variables (local variables, monitoring), call stacks, breakpoints, and so on. Basically all the features we need are here.

A less-than-good design is a variable, monitoring these places is too small, to see some long variables than the VS convenience. But fortunately we have debug console ah, directly on the variable name on the good.

Here is a reminder that in the upper-left corner of the dropdown select Debug mode, the two commonly used are Python and integrated terminal/console, the first is in the plug-in environment to debug the run, the second is the integrated console. The problem is that the first type does not support input (), so if you want to debug the program with input, choose integrated terminal/console or external terminal/console is also possible.

Git support

Integration of GIT support, this is a great feature, not only the line at the beginning of different colors to add, delete, modify the row, click the beginning of the color block, but also to show the contrast. Files that are modified with different colors and markup hints are also available in the resource manager.

When you want to commit, just switch to the left source control, and commit is OK.

Summarize

Vscode small, fast, cross-platform, cool interface, various extensions, it is time to change with the new Vscode.

This is after all Microsoft produced, casually from the VisualStudio project group pull a few people can shake sublime, atom several street (not to mention vim), let me have a once use up can not stop feeling.

Next, plan to introduce several useful vscode extensions.

Search for extended python in Vscode, this is the shipment:

After installation, reload. I have already installed it, so the Disable, uninstall button is displayed.

You can happily play with Python below. Isn't it super convenient?

Basic operations

Start your first Python code in Vscode, and the Python plugin's pylint feature will automatically prompt you, auto-complete, and error-Prompt as you type.

We need to remind you Pythoner, Vscode includes vs, tab is 4 spaces by default.

Several commonly used shortcut keys, estimated that the vser can be painless conversion:

    • The first is the F1/CTRL+SHIT+P Universal key, who knows with whom
    • Ctrl+p: File Switching
    • CTRL + SPACE: Auto prompt
    • f12/ctrl+ left button: Jump to Definition
    • SHIFT+F12: Preview Definition
    • CTRL+G: Jump Switch number
    • ctrl+/: Comment Toggle
    • Alt+↑↓: Move up and down the entire line
    • Ctrl+↑↓: Editor vertical scroll bar moves up or down, cursor does not move
    • Ctrl+backspace/delete: integer word/continuous blank deletion
    • ctrl+→←: Cursor Whole word movement
    • Ctrl+f find/ctrl+shift+f in the file to find, this is generic, like not to say AH.

Preview Definition diagram:

Debugging operations

F5 Debug runs anytime, anywhere. Note that the Vscode default after debugging, will stop in the first sentence, such as.

Debugging shortcuts are basically the same as vs.

    • F5: Debug/Continue,
    • F10: One-step skip,
    • F11: One Step into the
    • SHIFT+F11: Jump out.
    • F9: Toggle Breakpoint

The Left debug window shows the top-to-bottom debug mode, variables (local variables, monitoring), call stacks, breakpoints, and so on. Basically all the features we need are here.

A less-than-good design is a variable, monitoring these places is too small, to see some long variables than the VS convenience. But fortunately we have debug console ah, directly on the variable name on the good.

Here is a reminder that in the upper-left corner of the dropdown select Debug mode, the two commonly used are Python and integrated terminal/console, the first is in the plug-in environment to debug the run, the second is the integrated console. The problem is that the first type does not support input (), so if you want to debug the program with input, choose integrated terminal/console or external terminal/console is also possible.

Git support

Integration of GIT support, this is a great feature, not only the line at the beginning of different colors to add, delete, modify the row, click the beginning of the color block, but also to show the contrast. Files that are modified with different colors and markup hints are also available in the resource manager.

When you want to commit, just switch to the left source control, and commit is OK.

Summarize

Vscode small, fast, cross-platform, cool interface, various extensions, it is time to change with the new Vscode.

This is after all Microsoft produced, casually from the VisualStudio project group pull a few people can shake sublime, atom several street (not to mention vim), let me have a once use up can not stop feeling.

Next, plan to introduce several useful vscode extensions.

Vscode python plugin and configuration MS python plugin.

This is Microsoft's official Python plugin, which already comes with many features. Here is the plugin feature description, some of which I did the translation.

A) linting (Prospector, Pylint, Pycodestyle, Flake8, Pylama, Pydocstyle, mypy with config files and plugins) static code scanning ( Can be understood as code syntax and formatting error hints, support for multiple Linter)

b) IntelliSense (Autocompletion with support for PEP 484 and Pep 526) Smart hints (auto-complete, AutoComplete, including methods and variables in context)

c) Auto indenting automatic indent

d) Code formatting (AUTOPEP8, YAPF, with config files) automatically formatted

e) Code refactoring (Rename, Extract Variable, Extract method, sort Imports) refactoring (renaming, extracting variables, extracting methods, sorting Import)

f) Viewing references, code navigation, view signature see references, codes navigation, view signatures

g) Excellent debugging supports (remote debugging over SSH, mutliple threads, Django, flask) Perfect debugging support (remotely debug via SSH, multi-threading, Dja Ngo,flask)

h) Running and Debugging unit tests (unittest, pytest, nose, with config files) run and debug unit tests

i) Execute file or code in a Python terminal execute files or codes at the Python terminal

j) Snippets Code snippet

Visible already very strong, meet the basic needs. For example, to automatically format the code, you only need to press Alt+shift+f,vscode to call AUTOPEP8 Automatic Formatting code (digression, VisualStudio is ctrl+k,d).

But we are not content with this, we have to implement our style. For example snippets, such as we enter for, select the corresponding snippet in the Prompt box:

By clicking Enter or tab, it becomes:

For target_list in expression_list:    Pass

What do we do if we want to define our own snippets, for example, we want to quickly enter a for-XX in enumerator () way to traverse. First open the file-preferences-user code snippet. Vscode will prompt you to select the language, we enter Python and return, open the Python.json. The content format is JSON, and a new object is added below the root level, as follows:

"For in Enumerator": {        "prefix": "For/enum",        "body": [            "for ${1:index}, ${2:item} in Enumerate (${3:array}): ",            "    ${4:pass} "        ],        " description ":" For statement with enumerator "    }

This automatically generates when we enter For/enum and then press ENTER:

For index, item in enumerate (array):    Pass

The cursor rests on index and the word is selected, we can modify it directly, press TAB to switch to item, then array, pass.

    • Guides: Indentation hint

Some people say, Vscode already has indented the reference line, what also need guides do? It is true that the Vscode has indentation, but this guides is better than its own indent line, see:

The current level of indentation will turn red, at which level you are currently at a glance.

    • Vscode-icons file icon Set, support more file types, most important, Yan value high!

    • About debugging automatically pauses in the first sentence.

Here can be configured, that is, in the Lauch.json file, there is a "stoponentry": true, set to False can no longer pause.

    • Other

There are also some Python plug-in configuration, not one by one, we can be in the settings (file-preferences-settings) search. Including:

A) AUTOPEP8/YAPF: automatic format code;

b) Pylint-django: Compatible with Django Pylint, need to use PIP install;

c) Flakes8: Error prompt.

I hope you enjoy your stay.

Vscode the editor to write Python code

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.