python 的自定义 sublime-build 文件

Custom sublime-build file for python

我最近开始在 sublime text 3 中构建 python 脚本,我想构建一个自定义的 sublime 构建脚本,以便它可以从文件 "input.txt" 中获取输入并将其输出到控制台或文件 "output.txt".

要从文件中获取输入,您必须使用 open 函数打开文件:

file = open('file.txt')

接下来可以阅读内容:

contents = file.read()

如果要将内容或任何内容放入文件中,首先 create/open 文件:

file2 =  open('file2.txt', 'w')
file2.write(contents)

这会将变量 contents 的值写入文件。

https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files

对于仍在寻找解决方案的 Linux 用户:

您可以像这样在自定义构建文件中使用重定向运算符“<”和“>”:

 {
    "shell_cmd": "python \"${file}\" < inp.txt > out.txt"
 }

注意:对于其他平台,可以实现类似的想法。