Created
November 24, 2014 05:57
-
-
Save henryscala/29db7ba44c73eead0011 to your computer and use it in GitHub Desktop.
python script for changing line in a file in patch way
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
srcFileName = r'file1.java' | |
dstFileName = r'file2.java' | |
srcFile = open(srcFileName,'r') | |
dstFile = open(dstFileName,'w') | |
def listToStr(alist): | |
result =''; | |
for a in alist: | |
result += ', %s' % a | |
return result | |
def processLine(line): | |
try: | |
indexFun = line.index('someFunction') | |
except: | |
return line | |
indexLeftBracket = line.index('(') | |
indexRightBracket = line.index(')') | |
allArguments = line[indexLeftBracket+1:indexRightBracket] | |
argumentList = allArguments.split(',') | |
if len(argumentList) != 3: | |
return line | |
newLine = line[0:indexLeftBracket]+'('+argumentList[0]+', '+argumentList[1] + ', '+argumentList[1] +', '+argumentList[2] +');\n' | |
return newLine | |
for line in srcFile.readlines(): | |
newLine = processLine(line) | |
dstFile.write(newLine) | |
srcFile.close() | |
dstFile.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment