from csv import reader


def getChannelNames(fname):
    """
    Read Names of Electrodes from text file

    Input:
    ------
    -- fname - str - tab-delimeted textfile containing electrode number
                     and electrode-names
                     example:
                     1  C1
                     2  C3
    output:
    -------
    -- elecnames -  List of electrode names in ascending order as
                    determined by the electrode numbers in fname

    Example:
    --------
    >>> getChannelNames(_path.join(_path.join(_packdir, 'test_data'), \
            'elecnames.txt'))
    ['C1', 'C3']
    """
    filereader = reader(open(fname, 'r'), delimiter='\t', quotechar='"')
    elecnames = dict([(row[0].upper(),int(row[1])) 
        for row in filereader])
    from operator import itemgetter
    elecnames = sorted(iter(elecnames.items()), key=itemgetter(1))
    return [item[0] for item in elecnames]