For example, when you want to test standard input, it is troublesome to input every time, but reading an external file only increases garbage. If you want to test the original code as cleanly as possible, it seems better to override input ().
Write down the contents of the standard input you want to test as follows,
stdin_test = """1 2
3 4
5 6
"""
Override input () on the generator
def inp(t):
from io import StringIO
for i in StringIO(t):
yield i
input = inp(stdin_test).__next__
Example of use
a = [list(map(int, input().split())) for i in range(3)]
print(a)
>>> [[1, 2], [3, 4], [5, 6]]
I don't think there is a better way end
Recommended Posts