def parse_units(varname, variable):
    """Parses units based on variable input"""
    try:
        units = variable.units
        units = units.replace('-', '**-')
        units = units.replace('mmr', '1').replace('S', 'ohm**-1')
        units = units.replace('cm3', 'cm**3').replace('erg/g/s', 'erg/(g*s)')
        units = units.replace('none', '1')
    except:
        units = ''
        if varname == 'Z':
            units = 'cm'
    return units
