<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def append(self, listname, xy_idx, var_name, element_name):
 """Append variable names to the name lists"""

        self.resize()
        string = '{0} {1}'
        if listname not in ['unamex', 'unamey', 'fnamex', 'fnamey']:
            logger.error('Wrong list name for varname.')
            return
        elif listname in ['fnamex', 'fnamey']:
            string = '${0}\\ {1}$'

        if isinstance(element_name, list):
            for i, j in zip(xy_idx, element_name):
                # manual elem_add LaTex space for auto-generated element name
                if listname == 'fnamex' or listname == 'fnamey':
                    j = j.replace(' ', '\\ ')
                self.__dict__[listname][i] = string.format(var_name, j)
        elif isinstance(element_name, int):
            self.__dict__[listname][xy_idx] = string.format(
                var_name, element_name)
        else:
            logger.warning(
                'Unknown element_name type while building varname')