Created
July 31, 2018 04:59
-
-
Save jsburklund/9750239b8c5336f73b57fea2e0876fbc to your computer and use it in GitHub Desktop.
Parse SQL files for variables and replace them with python
This file contains hidden or 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
def parser(filename, values): | |
with open(filename, 'r') as f: | |
sql_text = f.read() | |
sql_text = sql_text.replace("$[", "{") | |
sql_text = sql_text.replace("]", "}") | |
sql_text = sql_text.format(**values) | |
print(sql_text) | |
if __name__=='__main__': | |
parser("test.sql", {"year": 2018}) | |
parser("test.sql", {"year": 1903}) | |
for year in [2016, 2017, 2019]: | |
parser("test.sql", {"year": year}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment