python in xycode

Posted by ExiaHuang on December 19, 2019

Agenda

Use xycode and python.

config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{
    "tasks": [
        {
            "label": "python:run",
            "description": "run python file",
            "cwd": "${fileDirname}",
            "command": "python \"${file}\""
        },
        {
            "label": "python:version",
            "description": "print python version",
            "command": "python --version"
        }
    ],
    "variables": {},
    "onSaveEvents": [
        {
            "label": "format python code",
            "description": "format python code",
            "filetypes": [".py"],
            "inActive": false,
            "command": "yapf \"${file}\" --style \"google\" -i"
        },
        {
            "label": "run python file",
            "description": "run python file",
            "filetypes": [".py"],
            "inActive": true,
            "cwd": "${fileDirname}",
            "command": "python \"${file}\""
        }
    ]
}

please install yapf if you want to auto format python code.

write hello world

1
print('hello world, python');

After save the file, you can see the result.