Last active
March 8, 2017 22:52
-
-
Save AndresMWeber/aad71cbbe89bcd4f480b23ba3982efe9 to your computer and use it in GitHub Desktop.
Takes locally definted variables from a script and takes any lowercase variables and creates an uppercase version, case study."
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
PRE = set(locals()) | |
a = 5 | |
B = 4 | |
def UPPER_CONVERT(vars): | |
for var in vars: | |
if not var.isupper(): | |
varname = var | |
# Obtain global variable value | |
exec('global %s' % var) | |
# Create a new global that is uppercase and holds the old lowercase variable value | |
exec('global %s\n%s = %s' % (varname.upper(), varname.upper(), var)) | |
DIFF = set(locals()) | |
UPPER_CONVERT(DIFF.difference(PRE)) | |
from pprint import pprint | |
pprint(locals()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment