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".
2 Answers
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
1 Comment
Snehasish Karmakar
I think the OP didn't mean file handling inside the python code itself.