Skip to content

Instantly share code, notes, and snippets.

@AndresMWeber
Last active March 8, 2017 22:52
Show Gist options
  • Save AndresMWeber/aad71cbbe89bcd4f480b23ba3982efe9 to your computer and use it in GitHub Desktop.
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."
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