如何从 Visual Studio Code 中执行 Python 代码 [英] How to execute Python code from within Visual Studio Code

查看:41
本文介绍了如何从 Visual Studio Code 中执行 Python 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这是您第一次打开任务:配置任务运行器",则需要选择其他";在下一个选择列表的底部.

这将显示属性,然后您可以根据自己的喜好更改这些属性.在这种情况下,您要更改以下属性;

  1. 将 Command 属性从 "tsc" (TypeScript) 更改为 "Python"
  2. 将 showOutput 从 silent" 更改为 Always"
  3. args(参数)从 [Helloworld.ts"] 更改为 [${file}"](文件名)
  4. 删除最后一个属性problemMatcher
  5. 保存所做的更改

您现在可以打开 .py 文件并使用快捷键 Ctrl + Shift + B (Windows) 或 Cmd + Shift + B(苹果).

Visual Studio Code was recently released and I liked the look of it and the features it offered, so I figured I would give it a go.

I downloaded the application from the downloads page, fired it up, messed around a bit with some of the features ... and then realized I had no idea how to actually execute any of my Python code!

I really like the look and feel/usability/features of Visual Studio Code, but I can't seem to find out how to run my Python code, a real killer because that's what I program primarily in.

Is there is a way to execute Python code in Visual Studio Code?

解决方案

Here is how to configure Task Runner in Visual Studio Code to run a .py file.

In your console, press Ctrl + Shift + P (Windows) or Cmd + Shift + P (Apple). This brings up a search box where you search for "Configure Task Runner"

If this is the first time you open the "Task: Configure Task Runner", you need to select "other" at the bottom of the next selection list.

This will bring up the properties which you can then change to suit your preference. In this case you want to change the following properties;

  1. Change the Command property from "tsc" (TypeScript) to "Python"
  2. Change showOutput from "silent" to "Always"
  3. Change args (Arguments) from ["Helloworld.ts"] to ["${file}"] (filename)
  4. Delete the last property problemMatcher
  5. Save the changes made

You can now open your .py file and run it nicely with the shortcut Ctrl + Shift + B (Windows) or Cmd + Shift + B (Apple).

这篇关于如何从 Visual Studio Code 中执行 Python 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆