def fix_reference_name(name, blacklist=None):
 import re
 name = ''.join(re.split('[^0-9a-zA-Z_]', name))
 while (name and (not re.match('([a-zA-Z]+[0-9a-zA-Z_]*)$', name))):
  if (not re.match('[a-zA-Z]', name[0])):
   name = name[1:]
   continue
 name = str(name)
 if (not name):
  name = 'data'
 if ((blacklist is not None) and (name in blacklist)):
  get_new_name = (lambda index: (name + ('%03d' % index)))
  index = 0
  while (get_new_name(index) in blacklist):
   index += 1
  name = get_new_name(index)
 return name

def fix_reference_name ( name , blacklist = None ) : import re name = '' . join ( re . split ( '[^0-9a-zA-Z_]' , name ) ) while ( name and ( not re . match ( '([a-zA-Z]+[0-9a-zA-Z_]*)$' , name ) ) ) : if ( not re . match ( '[a-zA-Z]' , name [ 0 ] ) ) : name = name [ 1 : ] continue name = str ( name ) if ( not name ) : name = 'data' if ( ( blacklist is not None ) and ( name in blacklist ) ) : get_new_name = ( lambda index : ( name + ( '%03d' % index ) ) ) index = 0 while ( get_new_name ( index ) in blacklist ) : index += 1 name = get_new_name ( index ) return name
return a syntax-valid python reference name from an arbitrary name .