code: def write(u, path):
      
      print("writing to: %s" % path)
      # This function implementation was chosen to be compatible across Python 2/3.
      f = open(path, "wb")
      try:
          b = u.encode(FILE_ENCODING)
          f.write(b)
      finally:
          f.close()
docs: Write a unicode string to a file (as utf-8).