title: Concatenate string literals to generate variable name
body: <h1>Question</h1>
  <p>In <code>python</code>, what is the shortest/easiest way to create a function which allows me to access a variable by concatenating two string literals to generate the variable's name?</p>
  <hr />
  <h1>Background</h1>
  <p>In <code>C</code>, I can do something like so:</p>
  <pre><code>#define CONCAT(x,y) x ## _ ## y
  </code></pre>
  <p>Then, later in my code, I could do something like:</p>
  <pre><code>int i = CONCAT(PRODUCT,BANANA).
  </code></pre>
  <p>Assuming a macro exists with the name PRODUCT_BANANA, its value is now assigned to <code>i</code>. I can accomplish something similar in shell scripts via indirection.</p>
  <hr />
  <h1>Question - Redux</h1>
  <p>How can I accomplish this same functionality in <code>python</code>? I'm doing this because I have a <code>python</code> class with thousands of variables for dozens of different products, i.e.</p>
  <pre><code>class A(object):
      BANANA_ADDRESS0 = 0xABCD;
      PINEAPPLE_ADDRESS0 = 0x1234;
      BANANA_ADDRESS1 = 0x4567;
      PINEAPPLE_ADDRESS1 = 0x1000;
  </code></pre>
  <p>I'd like to be able to have a function that can be, for example, executed via <code>someFunc(&quot;BANANA&quot;, &quot;ADDRESS0&quot;)</code>, resolve the value as <code>A.BANANA_ADDRESS0</code>, and return the associated value (<code>0xABCD</code>, in this case).</p>
  <hr />
  <h1>Extra</h1>
  <p>Assuming the above is possible, is it possible to have the function always interpret the supplied function arguments as string literals, so function calls don't need the arguments wrapped in single/double quotes? i.e. so it can be called via <code>someFunc(BANANA, ADDRESS0)</code>, rather than <code>someFunc(&quot;BANANA&quot;, &quot;ADDRESS0&quot;)</code>?</p>