title: How to do variable substitution in python
body: <p>I don't know what to call this but I've done it in TCL and Elixir. It's when you substitute a variable to make the code simpler. That's a terrible way of explaining it. The example will make it clear:</p>
  
  <p>Here's regular code:</p>
  
  <pre><code>def get(self, item):
      if item == 'name':
          return self.name
      elif item == 'age':
          return self.age
  </code></pre>
  
  <p>I'd like to turn that into something like this:</p>
  
  <pre><code>def get(self, item):
      return self.%{item}
  </code></pre>
  
  <p>Where it interprets the value in the variable <code>item</code> as the name of a variable. like I said, I've done stuff like this in other languages but I don't know what it's called and I don't know how to do it in python.</p>
  
  <p>Can you help me? What is this ability/style called? Also, how do you do it in Python?</p>
  
  <p>PS. Here's a trivial example from TCL</p>
  
  <pre><code>c:\repos\flow&gt;tclsh
  % set foo bar
  bar
  % set bar baz
  baz
  % puts $foo
  bar
  % puts [set $foo]
  baz
  </code></pre>
  
  <p>See how <code>[set $foo]</code> essentially told the interpreter to interpret <code>$foo</code>'s value as a variable name which was the variable <code>bar</code> then the command <code>puts</code> took <code>bar</code> as a variable and printed out its value which was the string <code>baz</code> </p>
  
  <p>You can even do this kind of thing with commands in Tcl</p>
  
  <pre><code>% set a puts
  puts
  % $a hello\ world
  hello world
  </code></pre>