Use Vscode to write Python's correct posture (reprint)

Source: Internet
Author: User

Recently in the study of Python, has been using notepad++ as an editor, accidentally found that the Vscode is attracted by its beauty value. After using it to find that it starts fast, plug-in rich, downloaded after installation almost without the configuration can be used directly, but also support markdown. Of course, the main thing is good-looking: p
:

Vscode Installing the Python plugin

    1. Open Vscode,ctrl+p
    2. Enter "ext install python", the search time may be longer
    3. Select the most downloaded plugin click Install (according to the network situation, the installation time is not sure, I installed a long time, my side has been downloaded so display uninstall)

To this side vscode can edit the Python code, edit the code by F5 to run. The first run will allow you to choose the environment and Python.

The default press F5 after the need to press the F5 program to run, if you want to press F5 run immediately need to Launch.json file "Stoponentry": true, Change to "Stoponentry": false.

Introduce a plugin,vscode-icons can make vscode on the left side of the explorer based on the file type Display icon configuration Flake8

When you write code after installing Flake8, the editor will prompt you for errors, and the code format will prompt

    1. Open command Line
    2. Enter "Pip Install Flake8"
    3. After the installation of Flake8 is successful, open Vscode, file, preferences, user settings, enter "Python.linting.flake8Enabled" in the Settings.json file: True

Configure YAPF

Automatically format code by pressing ALT+SHIFT+F in Vscode after installing YAPF

    1. Open command Line
    2. Enter "Pip Install YAPF"
    3. After the installation of YAPF is successful, open Vscode, file, preferences, user settings, enter "Python.formatting.provider" in the Settings.json file: "Yapf"

A few tips

    1. View the definition of a function or class
      CTRL + left mouse click on the function name or class name to jump to the definition, the function name or the class name by pressing F12 can also achieve the same function

    2. Change variable name
      Rename a variable by pressing F2 on the variable name

    3. Python breakpoint debugging
      Click on the left side of the line number to set breakpoints, and on the left side of the debug screen you can see the variable changes

    4. Hide the menu bar
      This is a personal habit, if you also feel that the menu bar is very annoying, you can click on the view---toggle menu bar, can hide the menu bar. Press the ALT key when you need the menu bar to view

    5. Set shortcut keys
      File, preferences, keyboard shortcuts, copy the contents of the entire curly brace of the desired modifier shortcut to the right Keybindings.json file, and then modify the value of "key" to the shortcut you need. I only modified the shortcut keys for copying one row and deleting a row.

At last

What needs to be supplemented or where there is a mistake to welcome everyone to point out (?? ' ω′? Reference

Python on Visual Studio Code

Pythonvscode
There are very detailed tutorials and demo gifs in this

Use Vscode to write Python's correct posture (reprint)

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.