<s> class CSVWriter ( object ) : <EOL> def __init__ ( self ) : <EOL> self . f = None <EOL> self . Columns = None <EOL> def Open ( self , columns , filename ) : <EOL> self . Columns = columns <EOL> self . f = open ( filename , '<STR_LIT:a>' ) <EOL> if self . Columns != None : <EOL> for k in self . Columns : <EOL> self . f . write ( k + '<STR_LIT:\t>' ) <EOL> self . f . write ( '<STR_LIT:\n>' ) <EOL> self . f . flush ( ) <EOL> def WriteLine ( self , line ) : <EOL> self . f . write ( line + '<STR_LIT:\n>' ) <EOL> self . f . flush ( ) <EOL> def WriteListEntry ( self , list ) : <EOL> for k in list : <EOL> if k != None : <EOL> val = str ( k ) . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) . replace ( '<STR_LIT:\t>' , '<STR_LIT:U+0020>' ) <EOL> else : <EOL> val = '<STR_LIT>' <EOL> self . f . write ( val + '<STR_LIT:\t>' ) <EOL> self . f . write ( '<STR_LIT:\n>' ) <EOL> self . f . flush ( ) <EOL> def Write ( self , list ) : <EOL> for d in list : <EOL> self . WriteEntry ( d ) <EOL> def WriteEntry ( self , d ) : <EOL> for k in self . Columns : <EOL> if d . has_key ( k ) : <EOL> val = str ( d [ k ] ) . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) . replace ( '<STR_LIT:\t>' , '<STR_LIT:U+0020>' ) <EOL> else : <EOL> val = '<STR_LIT>' <EOL> self . f . write ( val + '<STR_LIT:\t>' ) <EOL> self . f . write ( '<STR_LIT:\n>' ) <EOL> self . f . flush ( ) <EOL> def Close ( self ) : <EOL> self . f . close ( ) <EOL> self . f = None <EOL> def WriteAllResults ( filename , columns , list ) : <EOL> w = CSVWriter ( ) <EOL> w . Open ( columns , filename ) <EOL> w . Write ( list ) <EOL> w . Close ( ) </s>
