Skip to content

Instantly share code, notes, and snippets.

@ibarrajo
Created June 15, 2017 18:32
Show Gist options
  • Save ibarrajo/74a03b135079ee23f3ae0250de11fe4c to your computer and use it in GitHub Desktop.
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!
#!/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")
@davidrouten
Copy link

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!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment