fork download
  1. def third_party():
  2. a = input()
  3. b = input()
  4. print(a, b)
  5.  
  6. def my_code():
  7. # backup the input function
  8. original_input = __builtins__.input
  9. # patch the input function
  10. counter = 0
  11. input_queue = ['first automatic input', 'another one']
  12. def my_custom_input(*args, **kwargs):
  13. nonlocal counter
  14. if counter < len(input_queue):
  15. counter += 1
  16. return input_queue[counter - 1]
  17. else:
  18. return original_input(*args, **kwargs)
  19.  
  20. __builtins__.input = my_custom_input
  21.  
  22. # invoke the 3rd party
  23. third_party()
  24.  
  25. # restore the input function
  26. __builtins__.input = original_input
  27.  
  28. my_code()
Success #stdin #stdout 0.02s 9208KB
stdin
Standard input is empty
stdout
first automatic input another one