Created
April 15, 2013 15:17
-
-
Save j08lue/5388860 to your computer and use it in GitHub Desktop.
In Python source code file docstrings, replace dashes- by equals= using sed
This file contains 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
"""In Python source code file docstrings, replace dashes- by equals= using sed""" | |
import subprocess | |
import os | |
def sed_replace_patterns(wdir,maxdash=20,mindash=2): | |
for n in xrange(maxdash,mindash+1,-1): | |
pstr = '-'*n # pattern | |
sstr = '='*n # substitute | |
sedstr = 's/{}/{}/g'.format(pstr,sstr) | |
sedcmd = ['sed','-i',sedstr,wdir+'/*.py'] | |
print 'executing '+' '.join(sedcmd) | |
subprocess.check_call(sedcmd) | |
if __name__ == "__main__": | |
wdir = '.' | |
os.chdir(wdir) | |
print os.getcwd() | |
sed_replace_patterns(wdir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment