code: def tofile(path=""):
      
      if not path:
          path = os.path.join(os.getcwd(), "{}.txt".format(__name__))
  
      global stream
      orig_stream = stream
  
      try:
          stream = FileStream(path)
          yield stream
  
      finally:
          stream = orig_stream
docs: Instead of printing to a screen print to a file
  
      :Example:
          with pout.tofile("/path/to/file.txt"):
              # all pout calls in this with block will print to file.txt
              pout.v("a string")
              pout.b()
              pout.h()
  
      :param path: str, a path to the file you want to write to