(s, f=None, new_line=True)
Similar to print but with support to flush and output to a file.
Similar to print but with support to flush and output to a file.
Similar to print but with support to flush and output to a file .
def print_out(s, f=None, new_line=True):
  """Similar to print but with support to flush and output to a file."""
  if isinstance(s, bytes):
    s = s.decode("utf-8")

  if f:
    f.write(s.encode("utf-8"))
    if new_line:
      f.write(b"\n")

  # stdout
  out_s = s.encode("utf-8")
  if not isinstance(out_s, str):
    out_s = out_s.decode("utf-8")
  print(out_s, end="", file=sys.stdout)

  if new_line:
    sys.stdout.write("\n")
  sys.stdout.flush()
def print_out ( s , f = None , new_line = True ) : if isinstance ( s , bytes ) : s = s . decode ( "utf-8" ) if f : f . write ( s . encode ( "utf-8" ) ) if new_line : f . write ( b"\n" ) # stdout out_s = s . encode ( "utf-8" ) if not isinstance ( out_s , str ) : out_s = out_s . decode ( "utf-8" ) print ( out_s , end = "" , file = sys . stdout ) if new_line : sys . stdout . write ( "\n" ) sys . stdout . flush ( )