Skip to content

Instantly share code, notes, and snippets.

@youandhubris
Last active April 1, 2018 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youandhubris/c1527902e72260790df33d48272b4ccf to your computer and use it in GitHub Desktop.
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.
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