Sublime Text 3的构建系统问题 - 无法从运行的程序获取输入 [英] Issue with Sublime Text 3's build system - can't get input from running program

查看:374
本文介绍了Sublime Text 3的构建系统问题 - 无法从运行的程序获取输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获得Sublime Text 3(构建3049,如果这很重要)运行一个Python脚本。一个简单的两个线程

I'm trying to get Sublime Text 3 (build 3049, if that matters) to run a Python script. A simple two liner

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.

这是,看到类似问题的数量,一个问题,相当多的用户,所以我经历了那些,尝试...的东西。做了一个exec.py文件的副本,评论一行,做了一个新的pythonw构建文件,试图搞砸了构建文件...没有什么似乎工作。

This is, seeing the number of similar questions on the side, a problem for quite a number of users, so I went through those and tried ... stuff. Made a copy of exec.py file, commented that one line, made a new pythonw build file, tried messing about with the build file ... nothing seems to work.

推荐答案

首先,因为你使用Sublime Text 3,重新使用一个开发版本,你必须是一个注册用户(好!),我建议升级到3053,最新版本,因为较新的通常在已知问题固定的方面更好。其次,只是FYI,在 docs.sublimetext.info上有一套相当完整的(非官方)文档。他们组织得很好,很新,并且比sublimetext.com上的官方有更多的理由。最后,为了回应您的评论,Sublime来了与内置的略微削减版本的Python。 ST2有2.6,而ST3有3.3,所以如果你编写插件,你需要符合这些语言规范。您可以从控制台运行任意命令打开 Ctrl `

First off, since you're using a dev build, you must be a registered user (good!) and I'd recommend upgrading to 3053, the latest version, as newer is often better in terms of known issues being fixed. Second, just FYI, there's a fairly complete set of (unofficial) docs at docs.sublimetext.info. They're well-organized, pretty up-to-date, and cover a lot more ground than the "official" ones on sublimetext.com. Finally, in response to your comment, Sublime comes with a slightly stripped-down version of Python built-in. ST2 has 2.6, while ST3 has 3.3, so if you write plugins you'll need to conform to those language specifications. You can run arbitrary commands from the console by hitting Ctrl`.

正如几个SO问题所述,Sublime Text本身不能处理 raw_input() input()。其他语言也是如此 - Ruby的获得,Java的 Scanner 类,Node的 readline 类等。最简单的短期解决方案是获得打包控制尚未安装,请安装 SublimeREPL 。它允许您通过运行的REPL传输或运行部分或全部代码(您需要先启动一个)。

As documented in several SO questions, Sublime Text on its own cannot handle input via raw_input() or input(). The same is true of other languages as well - Ruby's gets, Java's Scanner class, Node's readline class, etc. The easiest short-term solution is to get Package Control if you don't already have it, then install SublimeREPL. It allows you to transfer or run part or all of your code through the running REPL (you'll need to start one first).

如果您运行的代码不能很好地与SublimeREPL(例如,你使用C / C ++ / Java /等,并需要在运行前编译代码),或者你只是想独立于Sublime运行它,你需要使您自己的构建系统。将以下内容另存为 Packages / User / Python_cmd.sublime-build

If the code you're running doesn't play well with SublimeREPL (for instance, you're using C/C++/Java/etc. and need to compile code before it runs), or you just want to run it independently of Sublime, you'll need to make your own build system. Save the following as Packages/User/Python_cmd.sublime-build:

{
    "cmd": ["start", "cmd", "/k", "c:/python27/python.exe", "$file"],
    "selector": "source.python",
    "shell": true,
    "working_dir": "$file_dir"
}

根据需要更改Python可执行文件的路径。然后,转到工具 - >构建系统并选择 Python_cmd ,当您点击 Ctrl B 新的 cmd 窗口将打开,您的文件正在运行。在程序运行完成后, / k 选项返回到命令提示符,而不关闭窗口。

changing the path to your Python executable as appropriate. Then, go to Tools -> Build System and select Python_cmd, and when you hit CtrlB to build, a new cmd window will open up with your file running. The /k option returns to the command prompt, without closing the window, after your program is done running so you can examine output, tracebacks, etc.

这篇关于Sublime Text 3的构建系统问题 - 无法从运行的程序获取输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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