Skip to content

Instantly share code, notes, and snippets.

@scraperdragon
Created September 7, 2012 10:51
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 scraperdragon/3665070 to your computer and use it in GitHub Desktop.
Save scraperdragon/3665070 to your computer and use it in GitHub Desktop.
Make an identifier out of a string
def makeidentifier(s):
import string
s=s.strip().replace(' ','_')
valid_chars = "_%s%s" % (string.ascii_letters, string.digits)
out=''.join(c for c in s if c in valid_chars)
if len(out)==0:
return '_'
else:
return out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment