![](/img/trans.png)
[英].sublime-build files not present after Sublime Text 3 install
[英]Custom sublime-build file for python
我最近開始以sublime文本3構建python腳本,我想構建一個自定義的sublime構建腳本,以便它可以從文件“ input.txt”中獲取輸入並將其輸出到控制台或文件“ output.txt”中。
對於那些仍在尋找解決方案的Linux用戶:
您可以像這樣在自定義構建文件中使用重定向運算符“ <”和“>”:
{
"shell_cmd": "python \"${file}\" < inp.txt > out.txt"
}
注意 :對於其他平台,可能會實現類似的想法。
要從文件中獲取輸入,必須使用open
功能打開文件:
file = open('file.txt')
然后您可以閱讀內容:
contents = file.read()
如果要將內容或任何內容放入文件中,請首先創建/打開文件:
file2 = open('file2.txt', 'w')
file2.write(contents)
這會將變量contents
的值寫入文件。
https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.