Forum Archive

Standard Input from a File

greedydita

I'd like to use Pythonista for coding competitions (practice). On my Windows box, I typically create one file for the solution and multiple files for each test case. Running the solution with a test case looks something like this:

python solution.py < input1
or
cat input1 | python solution.py

Any suggestion for how to achieve this in Pythonista? Ideally I don't want to open a file from within solution.py, but if there is no other solution I'll create some boilerplate code at the beginning of my solutions. I'd like to be able to copy/paste the solution (under the boilerplate if necessary) into the judgeing application. Thus, I would not need to change the following line before submitting for judement:
n,m = map(int, raw_input().split())
for input:
8 3

thanks!

blmacbeth

Look into StaSH. I don't have the link offhand, but if you search the forums it should turn up. It has a terminal emulator built in that should handle piping.

greedydita

StaSH did the trick!

I followed the instructions here:
https://omz-forums.appspot.com/pythonista/post/5894157600030720

After installing I could run solution and test with this command:
cat input1 | python solution.py

thanks a lot blmacbeth

blmacbeth

Glad to help :)