def safe_write(filename, contents):
 dirname = os.path.dirname(filename)
 if (not os.path.exists(dirname)):
  os.makedirs(dirname)
 with open(filename, 'w') as fh:
  fh.write(contents.encode('utf-8', 'ignore'))
  fh.close()

def safe_write ( filename , contents ) : dirname = os . path . dirname ( filename ) if ( not os . path . exists ( dirname ) ) : os . makedirs ( dirname ) with open ( filename , 'w' ) as fh : fh . write ( contents . encode ( 'utf-8' , 'ignore' ) ) fh . close ( )
normalize and write to filename write contents to the given filename .