Python: Accessing an attribute using a variable
<p>How do I reference <code>this_prize.left</code> or <code>this_prize.right</code> using a variable?</p>

<pre><code>from collections import namedtuple

import random 

Prize = namedtuple("Prize", ["left", "right"]) 

this_prize = Prize("FirstPrize", "SecondPrize")

if random.random() &gt; .5:
    choice = "left"
else:
    choice = "right"

#retrieve the value of "left" or "right" depending on the choice

print "You won", this_prize.choice

AttributeError: 'Prize' object has no attribute 'choice'
</code></pre>
