Skip to content

Instantly share code, notes, and snippets.

@atmb4u
Last active February 19, 2019 03:20
Show Gist options
  • Save atmb4u/38baf2138b4b7d970afe68f48d73191b to your computer and use it in GitHub Desktop.
Save atmb4u/38baf2138b4b7d970afe68f48d73191b to your computer and use it in GitHub Desktop.
anything to snakecase
#!/usr/bin/env python
"""
Usage: Put this script in any /bin folder in the PATH and run
snakecase "Hello World (123).csv"
OR
Download this snippet and run
python snakecase "Hello World (123).csv"
Output: hello_world_123.csv
"""
import re, sys
input_string = sys.argv[1]
print(re.sub(" ", "_", re.sub(r'[^\w \.]', '', input_string.strip(" ")).lower()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment