<s> from __future__ import unicode_literals , division , absolute_import , print_function <EOL> import csv <EOL> class CSVReader ( object ) : <EOL> def __init__ ( self , path , as_dict = True , value_converter = None ) : <EOL> self . _file_path = path <EOL> self . _as_dict = as_dict <EOL> self . _content = None <EOL> self . value_converter = value_converter or ( lambda x , y : y ) <EOL> @ property <EOL> def file_path ( self ) : <EOL> return self . _file_path <EOL> @ property <EOL> def as_dict ( self ) : <EOL> return self . _as_dict <EOL> def read ( self ) : <EOL> with open ( self . _file_path , '<STR_LIT:r>' ) as csv_file : <EOL> csv_reader = csv . reader ( csv_file ) <EOL> self . _content = [ ] <EOL> if self . as_dict : <EOL> header_row = next ( csv_reader ) <EOL> for line in csv_reader : <EOL> block = { } <EOL> for key , value in dict ( zip ( header_row , line ) ) . items ( ) : <EOL> block [ key ] = self . value_converter ( key , value ) <EOL> self . _content . append ( block ) <EOL> else : <EOL> for line in csv_reader : <EOL> self . _content . append ( line ) <EOL> @ property <EOL> def content ( self ) : <EOL> if self . _content is None : <EOL> self . read ( ) <EOL> return self . _content </s>
