Created
June 15, 2017 18:32
-
-
Save ibarrajo/74a03b135079ee23f3ae0250de11fe4c to your computer and use it in GitHub Desktop.
Developers who use spaces make more money than those who use tabs. Let's automate that!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# So.. developers who use spaces make more money than those who use tabs huh? | |
# https://stackoverflow.blog/2017/06/15/developers-use-spaces-make-money-use-tabs/ | |
# We can automate that promotion! | |
from __future__ import print_function | |
import os | |
import fnmatch | |
from fileinput import FileInput | |
SUPREME_WHITESPACE = " " | |
LESSER_WHITESPACE = "\t" | |
def instant_promotion(file_pattern): | |
for path, dirs, files in os.walk(os.path.expanduser("~"), topdown=True): | |
files = [os.path.join(path, filename) for filename in fnmatch.filter(files, file_pattern)] | |
dirs[:] = [d for d in dirs if not d[0] == '.'] | |
for l in FileInput(files, inplace=True, backup=".old"): | |
print(l.replace(LESSER_WHITESPACE, SUPREME_WHITESPACE), end="") | |
exit("dont't run random code from the internet..") | |
instant_promotion("*.py") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this, just fantastic. I just ran this script over all of my most recent merge requests and was almost immediately called into my boss's office and offered a 15% raise! Thanks instant-promotion.py!!