Visual Studio Code builds a python development environment

Source: Internet
Author: User
Tags svn
Python installation (included under Mac)
Visual Studio Code installation
Visual Studio Code install python plugin
Command + P Open command input interface
Enter ext install python to install the python plugin
Install and configure flake8 (automatic error checking tool)
Install flake8 pip install flake8 in python environment
Modify the configuration in User-Preferences-Workspace Settings (user settings are also available) "python.linting.flake8Enabled": true
Installation configuration yapf (automatic formatting code tool)
Sybase environment install yapf pip install yapf
Modify the configuration in User-Preferences-Workspace Settings (user settings are also available) "python.formatting.provider": "yapf"
Command + shift + F formatting code
Configuring Command + Shift + B to run the code

Open or create a new python source file, press the shortcut key Ctrl+Shift+B to run, VSC will prompt No task runner configured., click “Configure Task Runner”, select “Others”, enter the following content and save:


{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "${workspaceRoot}/venv/bin/python",
    "isShellCommand": true,
    "args": ["${file}"],
    "showOutput": "always"
}



Configure the vituentev runtime environment
Modify the configuration in User-Preferences-Workspace Settings (user settings are also available) "python.pythonPath": "${workspaceRoot}/venv/bin/python"
Install Linting (Code Format Checker)
Install linting pip install pylint in python environment
After installing the python plugin, pylint is enabled by default.
Configure display space characters
Modify the configuration in User-Preferences-Workspace Settings (user settings are also available) "editor.renderWhitespace": "all"
Configuration ignores non-code file display
Modify configuration in User-Preferences-Workspace Settings (user settings are also available)
"files.exclude":{ "**/.git": true, "**/.svn": true, "**/.hg": true, "**/.DS_Store": true, "** /*.pyc":true }
Full workspace configuration file

// Put the settings in this file to override the default and user settings.
{
"python.pythonPath":"${workspaceRoot}/venv/bin/python",
"editor.renderWhitespace":"all",
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.formatting.provider":"yapf",
//Configure glob mode to exclude files and folders.
"files.exclude":{
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/.DS_Store": true,
"**/*.pyc": true
}
}



Configuration code snippet
Code—Preferences—user code snippets, select python
In the configuration file, enter the content you want to define. The fields have the following meanings:

Prefix: This parameter is a quick entry to use the code segment. For example, if the log is used, the input log will be intellisense.
Body : This is the body of the code segment. The code to be set is placed here, and the line break between strings is separated by \r\n newline. Note that if the value contains special characters, it needs to be escaped.
$1 : This is the location of the cursor.
$2: After using this parameter, the next position of the cursor will start another line, press tab to switch quickly.
Description : description of the code segment, description when using IntelliSense


The complete configuration file example is as follows:


{
/*
//Place your snippets forPython here.Each snippet is defined under a snippet name and has a prefix, body and
// description.The prefix is what is used to trigger the snippet and the body will be expanded and inserted.Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another}for placeholders.Placeholderswith the
// same ids are connected.
//Example:
"Print to console":{
"prefix": "log",
"body":[
"console.log(‘$1‘);",
"$2"
],
"description":"Log output to console"
}
*/
"Input Note": {
"prefix": "itne",
"body":[
"‘‘‘",
"Function Name : diff_Json_Same",
"Function: General Comparison xx Method",
"Input Parameters: jsonastr, jsonbstr",
"Return Value : None",
"‘‘‘"
],
"description": "Input the class or function notes!"
}
}


Call method: Enter itne in the python file, enter the definition code snippet
Configuration shortcut
Code - Preferences - Keyboard Mapping Extension
Configuration topic
Code—Preferences—Color Themes
Code—Preferences—File Icon Theme

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.