The correct posture to write python with VSCode

I was learning python recently, and I have been using notepad++ as an editor before. I stumbled upon VScode and was attracted by its beauty. After using it, I found that it starts quickly and has rich plug-ins. After downloading and installing, it can be used directly without any configuration, and it also supports markdown. Of course, the main thing is to look good :p

Effect picture:

renderings

VScode download address

Install the python plugin

  1. Open VScode, Ctrl+p
  2. Enter "ext install python", the search time may be longer
  3. Select the plug-in with the highest download volume and click to install (according to the network situation, the installation time is uncertain, I installed it for a long time, I have already downloaded it here, so it shows uninstall)

python plugin installation

At this point, VScode can edit the python code. After editing the code, press F5 to run it. The first run will let you choose the environment, just choose python.

By default, you need to press F5 again to run the program after pressing F5. If you want to press F5 to run immediately, you need to change "stopOnEntry": true in the launch.json file to "stopOnEntry": false.

Recommend a plugin, vscode-icons can make the resource manager on the left side of VScode display icons according to the file type

configure flake8

After installing flake8, when writing code, the editor will prompt where is the error, and the code format is not standardized.

  1. open command line
  2. Type "pip install flake8"
  3. After installing flake8 successfully, open VScode, File -> Preferences -> User Settings, enter "python.linting.flake8Enabled": true in the settings.json file

flake8 configuration

flake8 renderings

configure yapf

After installing yapf, press Alt+Shift+F in VScode to automatically format the code

  1. open command line
  2. Type "pip install yapf"
  3. After installing yapf successfully, open VScode, File->Preferences->User Settings, enter "python.formatting.provider": "yapf" in the settings.json file

yapf configuration

yapf renderings

a few tips

  1. View the definition of a function or class
    Ctrl + left mouse button Click the function name or class name to jump to the definition, and press F12 on the function name or class name to achieve the same function

  2. Change
    the variable name Press F2 on the variable name to rename the variable

  3. Python breakpoint debugging
    Click on the left side of the line number to set a breakpoint, and you can view the changes of variables in the debugging interface on the left
    debug

  4. Hiding the menu bar
    is a personal habit. If you also feel that the menu bar is annoying, you can click View -> Switch Menu Bar to hide the menu bar. When you need the menu bar, press the Alt key to view it

  5. Set the shortcut key
    file -> Preferences -> Keyboard shortcuts, copy the contents of the entire curly brackets of the shortcut keys you need to modify to the keybindings.json file on the right, and then modify the value of "key" to the shortcut key you need That's it. I only modified the shortcut keys for copying a line and deleting a line here.
    Shortcut settings

finally

If you have anything to add or if you have any mistakes, please point out (。・`ω´・)

refer to

Python on Visual Studio Code

There are very detailed tutorials and demo gifs in pythonVSCode

Effect picture:

renderings

VScode download address

Install the python plugin

  1. Open VScode, Ctrl+p
  2. Enter "ext install python", the search time may be longer
  3. Select the plug-in with the highest download volume and click to install (according to the network situation, the installation time is uncertain, I installed it for a long time, I have already downloaded it here, so it shows uninstall)

python plugin installation

At this point, VScode can edit the python code. After editing the code, press F5 to run it. The first run will let you choose the environment, just choose python.

By default, you need to press F5 again to run the program after pressing F5. If you want to press F5 to run immediately, you need to change "stopOnEntry": true in the launch.json file to "stopOnEntry": false.

Recommend a plugin, vscode-icons can make the resource manager on the left side of VScode display icons according to the file type

configure flake8

After installing flake8, when writing code, the editor will prompt where is the error, and the code format is not standardized.

  1. open command line
  2. Type "pip install flake8"
  3. After installing flake8 successfully, open VScode, File -> Preferences -> User Settings, enter "python.linting.flake8Enabled": true in the settings.json file

flake8 configuration

flake8 renderings

configure yapf

After installing yapf, press Alt+Shift+F in VScode to automatically format the code

  1. open command line
  2. Type "pip install yapf"
  3. After installing yapf successfully, open VScode, File->Preferences->User Settings, enter "python.formatting.provider": "yapf" in the settings.json file

yapf configuration

yapf renderings

a few tips

  1. View the definition of a function or class
    Ctrl + left mouse button Click the function name or class name to jump to the definition, and press F12 on the function name or class name to achieve the same function

  2. Change
    the variable name Press F2 on the variable name to rename the variable

  3. Python breakpoint debugging
    Click on the left side of the line number to set a breakpoint, and you can view the changes of variables in the debugging interface on the left
    debug

  4. Hiding the menu bar
    is a personal habit. If you also feel that the menu bar is annoying, you can click View -> Switch Menu Bar to hide the menu bar. When you need the menu bar, press the Alt key to view it

  5. Set the shortcut key
    file -> Preferences -> Keyboard shortcuts, copy the contents of the entire curly brackets of the shortcut keys you need to modify to the keybindings.json file on the right, and then modify the value of "key" to the shortcut key you need That's it. I only modified the shortcut keys for copying a line and deleting a line here.
    Shortcut settings

finally

If you have anything to add or if you have any mistakes, please point out (。・`ω´・)

refer to

Python on Visual Studio Code

There are very detailed tutorials and demo gifs in pythonVSCode

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324895198&siteId=291194637