So comprehensive! Your Best Partner for Python Programming - A Practical Guide to VSCode!

Students who have just learned Python may feel that it is a bit irritating to open Cmd every time they write Python, and students who have started Pycharm directly may feel that this software is too cumbersome and difficult to use. So is there any software that saves the step of opening CMD and can make up for the bulky characteristics of Pycharm?

Of course, the answer is VSCode.

The VSCode editor, which was born in 2015, can now be said to be one of the strongest editors at present. Under the endorsement of Microsoft, it has grown much faster than your long-established big brothers. It took less than 5 years to sit there. No. 1 market share. How did it succeed in such a short period of time? The answer is: simplicity and scalability .

Editor, simplicity is important . I still remember the first question I searched when I first used the Vim editor many years ago: how to quit Vim? The learning curve of a tool directly affects the size of the tool's audience, especially for editors. Anything that is complicated to use will eventually be replaced by something that is easier to use, but Vim has its unique advantages in operation and maintenance, so it is temporarily irreplaceable.

The irreplaceability of Vim is at the server level. For our desktop programming, the simpler and easier-to-use editor, the better. Don’t engage in tricky operations. If you mess up with tricky operations, you will end up annoying yourself. This is why VSCode is becoming more and more popular. It is not only easy to use, but also covers writing in almost all languages. If I have a small project that needs to involve all the front-end and back-end code, I can use VSCode as an editor to solve it, instead of The front end cuts Webstorm, the back end cuts Pycharm.

Without further ado, let's try using VSCode.

1. Installation

After all, it is a product of the uncle of Microsoft, you will hardly encounter problems installing VSCode, open:
https://code.visualstudio.com/

Select the version suitable for your system to download and install, all the way to the default:

a4be72bbf405e26964110868d48763da.png

2. Use

If you are not used to the English version of the editor, here is how to install the Chinese plugin:

2.1 Chinese plugin

1. Click View - Command Palette  (or type Ctrl + shift + P) to enter the command palette.

965938d7687ec0ee78b21da3280e3cb5.png

2.  Enter configure language and select Configure Display Language  .

1fa42f423fc3150c3cef30bfff202af0.png

3. Check whether there is an option of zh-cn, if so, directly select zh-cn to replace. Then follow the prompts to restart vscode to see the interface change back to Chinese.

If there is no zh-cn option, select install additional languages  ​​(add other language options), an extension window will pop up on the left, find the simplified Chinese in the extension window, click install to install, repeat  steps 1 and 2 to  select Chinese.

4d3b360cea59e406f5259e4bae9ad971.png

2.2 Using Terminal

This is the core of writing Python in VSCode. You can run Python directly in VSCode without opening the ugly CMD.

Click [ View - Terminal  ] or the direct shortcut key [ Ctrl + `  ] to open the terminal, and a CMD console will be generated below:

95b9b2fa9a06a07b227c196826093177.png

The latest changes you make here can be run directly from python xx.py:

68b16b7d970aaa07fbd66fda74c26611.png

However, pay attention to whether the current folder is in the same directory as the Python script file. If it is not in the same directory, you need to cd into it.

2.3 One-click operation

Many students want to run Python with one click instead of running it as a command. At this time, the Python extension is needed. Open the extension page, enter Python, and select the first one to install and install:

da3d862d6539a359a76028723caae773.png

Reload VSCode to take effect. After editing the code, press F5 to run it (if you don't need to enter parameters). The first run may let you choose the environment and choose Python.

By default, press F5 to enter DEBUG mode. You need to press F5 again to run the program. If you want to press F5 to run immediately, you need to change "stopOnEntry": true in the launch.json file to "stopOnEntry": false. The launch.json file can be found in the settings as shown below:

6dfc0dde9bdd606b7173f437b3244a26.png

3. Other extensions

3.1 Syntax hints, configure flake8

Writing code without syntax hints is actually a very uncomfortable thing. IDE does it for you directly, but VSCode requires you to configure it a little:

1.  Open the terminal, enter pip install flake8 to install flake8, I have already installed it, your prompt should be different from mine:

3a57ee125abc074a5a523175938dce10.png

2.  Enter "python.linting.flake8Enabled": true in the settings.json file

c85bba086cf168522142c5dc505c50c4.png

3.2 Automatically format code

Yapf is a tool open sourced by Google for formatting Python code, which can beautify the code with one click. Two specifications are supported: PEP8 and Google Style. The following steps are similar to 3.1, and the pictures will not be supplemented:

1.  Open Terminal

2.  Enter "pip install yapf" to install yapf

3.  Enter "python.formatting.provider": "yapf" in the settings.json file

4. Take a look and press the shortcut key  Alt+Shift+F  to automatically format the code.

3.3 File and folder icons

The default VSCode icons are not so detailed. There are only a few icon tips for important file types, which can be solved by installing vscode-icons. There is a vscode-icons-mac version for Mac. as the picture shows:

096fe5330310544eab62d48cc41213c4.png

The following file display is more detailed:

2c823c50ef6687a46c03176c5b8ac5a8.png

3.4 Generate annotation format

This is a plugin I highly recommend, search for docstring, currently ranked fourth, autoDocstring developed by Nils Werner, excellent representative:

db5a8629d7ed97307b12f4a9263f7405.png

After that, you just need to enter three double quotes after the function name and press Enter to generate a docstring comment:

6ffd60522e0b203bb9d8436d2e195990.png

Pressing Tab can directly switch the position that needs to be input, instead of clicking with the mouse, which speeds up the annotation efficiency. However, I don't like the position where the comment appears directly behind the three double quotation marks. It's a bit unsightly. Maybe this is the difference between the aesthetics of the East and the West? But even so, it's a very handy plugin.

If you like today's Python tutorial, please continue to follow us. If it is helpful to you, please like/watch 2a65118d81d939299259a37bfb6409fb.pngit below. If you have any questions, you can leave a message below!

Interested students can quickly join our planet

3 weeks zero basic introduction provides 10 lessons

12 interesting practical projects throughout the year including source code,

Reward outstanding Top3 students every month to send books

Professional Q&A group, nanny-style teaching by Dachang teachers

If you are not satisfied, feel free to refund within three days! 88 a year, now 16 yuan off

b6300b807c9f8a7e1761b5b260605af1.png

Scan the code to join, get started with zero basics in 3 weeks

推荐阅读:
入门: 最全的零基础学Python的问题  | 零基础学了8个月的Python  | 实战项目 |学Python就是这条捷径
干货:爬取豆瓣短评,电影《后来的我们》 | 38年NBA最佳球员分析 |   从万众期待到口碑扑街!唐探3令人失望  | 笑看新倚天屠龙记 | 灯谜答题王 |用Python做个海量小姐姐素描图 |碟中谍这么火,我用机器学习做个迷你推荐系统电影
趣味:弹球游戏  | 九宫格  | 漂亮的花 | 两百行Python《天天酷跑》游戏!
AI: 会做诗的机器人 | 给图片上色 | 预测收入 | 碟中谍这么火,我用机器学习做个迷你推荐系统电影
小工具: Pdf转Word,轻松搞定表格和水印! | 一键把html网页保存为pdf!|  再见PDF提取收费! | 用90行代码打造最强PDF转换器,word、PPT、excel、markdown、html一键转换 | 制作一款钉钉低价机票提示器! |60行代码做了一个语音壁纸切换器天天看小姐姐!|

The year's hottest copy

Click to read the original text to see 200 Python cases!

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326955052&siteId=291194637