Miscellaneous

  1. import sys
  2. import re
  3. from typing import Match, AnyStr, IO
  4.  
  5. # "typing.Match" describes regex matches from the re module
  6. x = re.match(r'[0-9]+', "15") # type: Match[str]
  7.  
  8. # Use IO[] for functions that should accept or return any
  9. # object that comes from an open() call (IO[] does not
  10. # distinguish between reading, writing or other modes)
  11. def get_sys_IO(mode='w'):
  12. # type: (str) -> IO[str]
  13. if mode == 'w':
  14. return sys.stdout
  15. elif mode == 'r':
  16. return sys.stdin
  17. else:
  18. return sys.stdout