从 ST 编辑器运行时如何在控制台中显示 python 脚本的结果? [英] How to show result of python script in a console when running from ST editor?

查看:74
本文介绍了从 ST 编辑器运行时如何在控制台中显示 python 脚本的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Sublime Text 的新手,所以到目前为止还不熟悉它的内部结构.据我所知,问题可能与 这个.

I'm new to Sublime Text so am unfamiliar with its internals so far. From what I could tell the problem could be something related to this.

我有一个 python 脚本

I have a python script

var = raw_input("Enter something: ")
print "You entered ", var

要求输入,等待输入,然后在 Windows 控制台提示中打印出来.

which asks for input, waits for it, then prints it out in windows console prompt.

如何在构建"时制作 ST3 以在控制台窗口中显示结果?

How do I make ST3 upon "building" to show the results in a console window?

推荐答案

这真的很简单,只需发出一个命令来启动一个新的 cmd.exe.

It's really simple just issue a command to start a new cmd.exe.

start cmd /K python main.py

查看这里了解更多(古代)

/k 标志将其他命令管道"到 cmd.exe 并运行,直到您自己退出 shell,这在您想查看跟踪时很有用.

The /k flag "pipes" the other commands to cmd.exe and runs until you exit the shell yourself, useful for when you want to see traces.

/C 标志将其他命令管道"到 cmd.exe 并运行,直到 python 程序完成.

The /C flag "pipes" the other commands to cmd.exe and runs until the python program has finished.

所以在你的项目文件中你应该有这样的东西:

So in your project-file you should have something like this:

"build_systems": [
    {
        "name": "RunPY",
        "cmd": ["start", "cmd", "/K", "python", "main.py"],
        "shell": true,
        "working_dir": "<project_path>"
    },

]

当我们讨论 Sublime 中的 build_systems 主题时,我想推荐插件 BuildSwitcher,它在 ST3 上工作正常,只是当您在项目文件中添加新构建时并不总是注意到.这也意味着您必须为 ST3 手动安装插件.

While we're on the topic of build_systems in Sublime I would like to recommend the plugin BuildSwitcher, it works okay on ST3, it just doesn't always notice when you've added a new build in your project file. This also means that you have to install the plugin manually for ST3.

使用该插件,您只需按几下键即可轻松定义和运行不同的构建.真正节省时间.

With that plugin you can easily define and run different builds with just a few key-strokes. A real timesaver.

这篇关于从 ST 编辑器运行时如何在控制台中显示 python 脚本的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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