def upload_read(infile, table):
    """
    Reads a table from a MagIC upload (or downloaded) txt file, puts data in a
    list of dictionaries
    """
    delim = 'tab'
    hold, magic_data, magic_record, magic_keys = [], [], {}, []
    f = open(infile, 'r')
    line = f.readline()[:-1]
    file_type = line.split('\t')[1]
    if file_type == 'delimited':
        file_type = line.split('\t')[2]
    if delim == 'tab':
        line = f.readline()[:-1].split('\t')
    else:
        f.close()
        print('only tab delimitted files are supported now')
        return
    while file_type != table:
        while line[0][0:5] in f.readlines() != '>>>>>':
            pass
        line = f.readline()[:-1]
        file_type = line.split('\t')[1]
        if file_type == 'delimited':
            file_type = line.split('\t')[2]
        ine = f.readline()[:-1].split('\t')
    while line[0][0:5] in f.readlines() != '>>>>>':
        for key in line:
            magic_keys.append(key)
        for line in f.readlines():
            rec = line[:-1].split('\t')
            hold.append(rec)
        for rec in hold:
            magic_record = {}
            if len(magic_keys) != len(rec):
                print('Uneven record lengths detected: ', rec)
                input('Return to continue.... ')
            for k in range(len(magic_keys)):
                magic_record[magic_keys[k]] = rec[k]
            magic_data.append(magic_record)
    f.close()
    return magic_data
