Skip to content

Instantly share code, notes, and snippets.

@j08lue
Created April 15, 2013 15:17
Show Gist options
  • Save j08lue/5388860 to your computer and use it in GitHub Desktop.
Save j08lue/5388860 to your computer and use it in GitHub Desktop.
In Python source code file docstrings, replace dashes- by equals= using sed
"""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