title: python: is it possible to load values from json and automatically match their keys to existing variables to assign values?
body: <p>I'm new to python and have heard it has some interesting metaprogramming features which I know nothing about. </p>
  
  <p>I'm not sure this exists, but is it possible to load a json file and search for keys that match variables in the existing script, and if there is a match, assign them? </p>
  
  <p>Additionally, if I do make these assignments, is it possible to detect that the loading script (a config script in this case) contains variable names that the json file does not have? In this case I would add these new variable names to the json file and save values, to be loaded on next run. </p>
  
  <p>for example, I'd like to do something where somewhere in the following code, a list of variables attached to the executing script would be put into a list, and that list could then be used to match keys in a json file, and also to assign the variables new values in the executing script. </p>
  
  <pre><code>config.py
  
  MAX_LIMIT = 100
  FOO = 'test'
  BAR = 'other test'
  
  def get_variable_names():
      return list_of_variables_in_config.py
  
  def load_config():
      vars = get_variable_names()
  
      with open('config.json') as data_file:  
  
          config = json.load(config_file)
          for k in config.keys():
              if k in vars:
                  vars[k] = config[k]
          for v in vars:
              if not v in config.keys():
                  config[v] = vars[v]   
  
  write_config(config)
  
  def print_vars():
      print('MAX_LIMIT = ', MAX_LIMIT)
      print('FOO = ', FOO)
      print('BAR = ', BAR)
  </code></pre>
  
  <p>output after running load config:</p>
  
  <pre><code>MAX_LIMIT = 23
  FOO = modified var
  BAR = other modified var
  </code></pre>
  
  <p>is this sort of thing possible? </p>
  
  <p>Thanks in advance </p>