def create_textfile_with_contents(filename, contents, encoding='utf-8'):
 ensure_directory_exists(os.path.dirname(filename))
 if os.path.exists(filename):
  os.remove(filename)
 outstream = codecs.open(filename, 'w', encoding)
 outstream.write(contents)
 if (contents and (not contents.endswith('\n'))):
  outstream.write('\n')
 outstream.flush()
 outstream.close()
 assert os.path.exists(filename), ('ENSURE file exists: %s' % filename)

def create_textfile_with_contents ( filename , contents , encoding = 'utf-8' ) : ensure_directory_exists ( os . path . dirname ( filename ) ) if os . path . exists ( filename ) : os . remove ( filename ) outstream = codecs . open ( filename , 'w' , encoding ) outstream . write ( contents ) if ( contents and ( not contents . endswith ( '\n' ) ) ) : outstream . write ( '\n' ) outstream . flush ( ) outstream . close ( ) assert os . path . exists ( filename ) , ( 'ENSURE file exists: %s' % filename )
creates a textual file with the provided contents in the workdir .