#NEWLINE# def append_files( in_file1 , character , in_file2 , out_file ) : #NEWLINE# #INDENT# '\n    Created on 24 Oct 2014\n    Created for use with Wonderware Archestra.\n    Takes a file1 and appends file2 contents joined by a character, line for line.\n    \n    USAGE:\n        %prog in_file1.csv %character in_file2.txt\n    @author: Roan Fourie\n    @mail: roanfourie@gmail.com\n    ' #NEWLINE# return_data = 0 #NEWLINE# write_data = '' #NEWLINE# i = 0 #NEWLINE# try : #NEWLINE# #INDENT# with open ( in_file1 , 'rt' ) as fi1 : #NEWLINE# #INDENT# lines1 = fi1 . readlines ( ) #NEWLINE# #UNINDENT# with open ( in_file2 , 'rt' ) as fi2 : #NEWLINE# #INDENT# lines2 = fi2 . readlines ( ) #NEWLINE# #UNINDENT# with open ( out_file , 'at' ) as fo : #NEWLINE# #INDENT# fo . seek ( 0 , 2 ) #NEWLINE# while ( i < len ( lines1 ) ) : #NEWLINE# #INDENT# lines1 [ i ] = lines1 [ i ] . rstrip ( '\n' ) #NEWLINE# fo . write ( ( ( lines1 [ i ] + character ) + lines2 [ i ] ) ) #NEWLINE# i = ( i + 1 ) #NEWLINE# #UNINDENT# #UNINDENT# print ( write_data ) #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# print ( 'Error in reading/writing file.' ) #NEWLINE# return_data = 2 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print ( 'Operation completed successfully.' ) #NEWLINE# return_data = 1 #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# fi2 . close ( ) #NEWLINE# fi1 . close ( ) #NEWLINE# fo . close ( ) #NEWLINE# print ( 'done' ) #NEWLINE# #UNINDENT# return return_data