Reputation: 6476
I recently started building python scripts in sublime text 3, I wanted to build a custom sublime build script such that it can take input from a file "input.txt" and output it into console or a file "output.txt".
Upvotes: 0
Views: 185
Reputation: 726
For those Linux users who are still looking for a solution to this:
You may make use of the redirection operators '<' and '>' inside the custom build file like this:
{
"shell_cmd": "python \"${file}\" < inp.txt > out.txt"
}
Note: For other platforms one may implement a similar idea.
Upvotes: 1
Reputation: 33
To take input from a file you must open the file with the open
function:
file = open('file.txt')
Then you can read the contents:
contents = file.read()
If you want to put the content or anything into a file, first create/open the file:
file2 = open('file2.txt', 'w')
file2.write(contents)
This will write the value of the variable contents
into the file.
https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
Upvotes: 0