Have you ever tried to take advantage of features like AtCoder's code testing and yukicoder's online execution? I wish I could run it in Python.
Well, in short, I wish I could read the .txt file with Python's input ().
This execution environment is Windows 10.
First of all, let's create an appropriate folder and insert the input.txt file for input and the main.py file containing the input () function into it.
If you move to the folder you created earlier at the command prompt and enter python main.py <input.txt, it's strange that you can read from the text file! !!
By the way, it works even if you do this with open (0) .read ().
I tried to do it with subprocess and killed it for 3 days after trial and error. This is Aho. In the following source code, the output that comes out with the print function comes out. The timeout option has a run time limit, shell = True and it works at a real command prompt. By the way, output comes out in byte type, so if you want to make it a character string type, please boil it with encode () or bake it ...
However, official documentation recommends that you do not use it as it can be a security vulnerability. Winodws If you specify the spell of destruction, not only Python but also Windows will disappear ...
import subprocess
print(subprocess.check_output('python main.py < input.txt',timeout=5,shell=True))
It seems that you can do more in detail with the Popen () function. I don't know at all. It will take about 5 days to understand.
It became a shit article. I will write more when I get more detailed. .. ..
Recommended Posts