Visual Studio Code进行Python开发

最近在使用Visual Studio Code进行python开发学习,VScode作为微软推出的编译器还是具有很强大的功能的,直接Ctrl+Shift+P即可进行插件的安装,如果是开发Python,还可以新建 task.json文件,然后按住 Ctrl+Shift+B键就会自动运行Python程序。


1. Python相关插件

使用Ctrl+Shift+P弹出顶栏后输入install,会列出可以安装的插件,输入Python后是Python开发相关的插件,选中插件按下回车即可自动安装,主要插件有:

Python

MagicPython

Python for VSCode

Python autopep8

以及 Backspace-plusplus 用于将4个空格作为一个tab

安装以上插件之后就可以进行Python开发了,以下是安装的插件



2. VSCode快捷功能

Ctrl+Shift+P 输入task,选中others,新建task.json文件,修改如下:

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

然后新建test.py文件,输入如下内容:

#!/usr/bin/python
#-*- encoding: utf-8 -*-

def test():
  print("python in VS code")
  
if __name__ == "__main__":
  test()
 此时保存文件,按下Ctrl+Shift+B即可自动运行文件,结果如下


这样就可以编辑完之后直接运行显示结果。

使用Ctrl+Shift+C可以调出 终端窗口。


3. 侧边栏不显示 __pycache__和.pyc文件

py文件执行后会生成.pyc文件,会影响侧边栏的使用,可以通过如下设置隐藏.pyc等中间文件

File -> perference ->User Setting 弹出用户设置文件,添加如下内容:

// Place your settings in this file to overwrite the default settings
{
	// Configure glob patterns for excluding files and folders.
	"files.exclude": {
		"**/.git": true,
		"**/.DS_Store": true,
        "*.pyc": true,
		"*.pyo" : true,
        "__pycache__" : true
	}
}

保存之后侧边栏就不会显示.pyc .pyo 和 __pycache文件了。





  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值