code: def linebuffered_stdout():
      
      if sys.stdout.line_buffering:
          return sys.stdout
      orig = sys.stdout
      new = type(orig)(orig.buffer, encoding=orig.encoding, errors=orig.errors,
                       line_buffering=True)
      new.mode = orig.mode
      return new
docs: Always line buffer stdout so pipes and redirects are CLI friendly.