How to test a Python script with an input file filled with testcases?

前端 未结 4 859
情歌与酒
情歌与酒 2021-01-24 18:00

I\'m participating in online judge contests and I want to test my code with a .in file full of testcases to time my algorithm. How can I get my script to take input from this .i

4条回答
  •  温柔的废话
    2021-01-24 18:47

    You can do this in a separate file.

    testmyscript.py

    import sys
    someFile= open( "somefile.in", "r" )
    sys.stdin= someFile
    execfile( "yourscript.py" )
    

提交回复
热议问题