29 Sep
2017
29 Sep
'17
10:45 a.m.
29.09.17 08:53, Wren Turkal пише:
This is meant to turn code like the following:
orig_stdin = sys.stdin
orig_stdout = sys.stdout
with open('/dev/tty', 'r+') as f:
sys.stdin = f
sys.stdout = f
name = input('Name? ')
sys.stdin = orig_stdin
sys.stdout = orig_stdout
print(name)
into something more like this:
with open('/dev/tty', 'r+') as f:
name = input('Name? ', fin=f, fout=f)
print(name)
Why not use just the following two lines? f.write('Name? ') name = f.readline() This falls to me in the category "not every two lines of the code should be added as a builtin".