#NEWLINE# def write_file_lines( lines , filename , mode = 'wt' , encoding = None ) : #NEWLINE# #INDENT# '\n    Write the content in ``lines`` to disk at ``filename``, line by line. Files\n    with appropriate extensions are compressed with gzip or bz2 automatically.\n    Any intermediate folders not found on disk are automatically created.\n    ' #NEWLINE# _make_dirs ( filename ) #NEWLINE# _open = ( gzip . open if filename . endswith ( '.gz' ) else ( bzip_open if filename . endswith ( '.bz2' ) else io . open ) ) #NEWLINE# try : #NEWLINE# #INDENT# with _open ( filename , mode = mode , encoding = encoding ) as f : #NEWLINE# #INDENT# for line in lines : #NEWLINE# #INDENT# f . write ( ( line + '\n' ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except TypeError : #NEWLINE# #INDENT# with _open ( filename , mode = mode ) as f : #NEWLINE# #INDENT# for line in lines : #NEWLINE# #INDENT# f . write ( ( line + '\n' ) )