Last active
April 1, 2018 14:33
-
-
Save youandhubris/c1527902e72260790df33d48272b4ccf to your computer and use it in GitHub Desktop.
Python script example for passing arguments, combining a list of files, replacing some content and saving as a new file.
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
import os | |
import re | |
import sys | |
# sys.args | |
workingDir = sys.argv[1] | |
scriptVersion = sys.argv[2] | |
#scripts paths | |
scripts = [ "fileA.js", | |
"fileB.js"] | |
#appending all the scripts inside the appender variable | |
appender = '' | |
for script in scripts: | |
path = workingDir + '/' + script | |
fileIn = open(path, 'rU') | |
appender = appender + fileIn.read() + '\n' | |
fileIn.close() | |
appender = appender.replace("Something Else", "Something " + scriptVersion) | |
#writing the content to file | |
fileOut = open(workingDir + '/Combined.js', 'w') | |
fileOut.write(appender) | |
fileOut.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment