0

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".

0

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

I think the OP didn't mean file handling inside the python code itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.