From daff15e873bfdc098eeebe3c9d6d7cbecff8a5c7 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Sun, 23 Feb 2020 23:19:40 +0100 Subject: [PATCH] rewrote some variable names and code style to make more sense to me --- variable_grabbler.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/variable_grabbler.py b/variable_grabbler.py index d6b2616..32594c3 100644 --- a/variable_grabbler.py +++ b/variable_grabbler.py @@ -1,7 +1,7 @@ #!/usr/bin/python2 print """ -Variable Grabbler - version 1.0 +Variable Grabbler - version 1.1 -------------------------------""" # definitions @@ -11,17 +11,21 @@ dir = os.path.dirname(os.path.abspath(__file__)) fext = "*.php" print "Opening config file..." -config = open(os.path.join(dir, "variable_grabbler.cfg"),"r") +config = open("variable_grabbler.cfg","r") parsed = json.load(config) for x in parsed: for path, dirs, files in os.walk(dir): for fname in fnmatch.filter(files, fext): fpath = os.path.join(path, fname) - with open(fpath) as f: - s = f.read() - s = s.replace("%" + x + "%", parsed[x]) - with open(fpath, "w") as f: - f.write(s) + file_in = open(fpath, "r") + file_content = file_in.read() + file_in.close() + + file_content = file_content.replace("%" + x + "%", parsed[x]) + + file_out = open(fpath, "w") + file_out.write(file_content) + file_out.close() config.close()