def __init__(self, fileName, uniqKeyCols=None, multiKeyCols=None, rowClass=None, typeMap=None, defaultColType=None, columns=None, columnNameMapper=None, ignoreExtraCols=False, isRdb=False, inFh=None, allowEmpty=False, dialect=csv.excel_tab): """Read TSV file into the object fileName - name of file, opened unless inFh is specified uniqKeyCols - name or names of columns to index with uniq keys, can be string or sequence multiKeyCols - name or names of columns to index, allowing multiple keys. can be string or sequence rowClass - class or class factory function to use for a row. Must take TSVReader and list of string values of columns. typeMap - if specified, it maps column names to the type objects to use to convert the column. Unspecified columns will not be converted. Key is the column name, value can be either a type or a tuple of (parseFunc, formatFunc). If a type is use, str() is used to convert to a printable value. defaultColType - if specified, type of unspecified columns columns - if specified, the column names to use. The header should not be in the file. ignoreExtraCols - should extra columns be ignored? isRdb - file is an RDB file, ignore second row (type map still needed). inFh - If not None, this is used as the open file, rather than opening it. Closed when the end of file is reached. allowEmpty - an empty input results in an EOF rather than an error. Should specify this if reading from a database query. """ reader = TSVReader(fileName, rowClass=rowClass, typeMap=typeMap, defaultColType=defaultColType, isRdb=isRdb, columns=columns, columnNameMapper=columnNameMapper, ignoreExtraCols=ignoreExtraCols, inFh=inFh, allowEmpty=allowEmpty, dialect=dialect) try: self.columns = reader.columns self.colTypes = reader.colTypes self.colMap = reader.colMap self.__buildIndices(uniqKeyCols, multiKeyCols) self.__readBody(reader) except Exception, e: raise TSVError("load failed", reader=reader, cause=e), None, sys.exc_info()[2]
def __init__(self, fileName): TSVReader.__init__(self, fileName, typeMap=typeMap)
def __init__(self, fileName, isRdb=False): TSVReader.__init__(self, fileName, typeMap=typeMap, isRdb=isRdb)