Skip to content

Instantly share code, notes, and snippets.

@Lucretiel
Created April 10, 2013 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lucretiel/5355246 to your computer and use it in GitHub Desktop.
Save Lucretiel/5355246 to your computer and use it in GitHub Desktop.
def make_variable_name(var):
valid_chars = set(string.letters + string.digits + '_')
def replace_char(char):
if char == '-':
return '_'
elif char in valid_chars:
return char
return ''
return ''.join(replace_char(char) for char in var)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment