Q: "TypeError: 'str' object is not callable' raised when method is called in an if statement (Python) I get a TypeError when I call a method in an if-block, but the method runs find when it is called outside an if block:
randenzyme() randomly chooses a key from a dictionary called enzymes:
def randenzyme(self):
    an_enzyme = choice(self.enzymes.keys())

It runs correctly with:
x = TCA()
x.randenzyme()

But "TypeError: 'str' object is not callable" is raised with:
x = TCA()
user_input = raw_input('> ')
if user_input == "1":
    x.randenzyme()

What is happening when the method is called in the if block?
UPDATE: Here is the full code
from random import *
import sys
class TCA(object):
    def __init__(self):
        self.enzymes = {}
        self.enzymes['citrate synthase'] = ('oxaloacetate', 'citrate')
        self.enzymes['aconitase'] = ('citrate', 'isocitrate')
        self.enzymes['isocitrate dehydrogenase'] = ('isocitrate', 'alpha-ketoglutarate')
        self.enzymes['alpha-ketoglutarate dehydrogenase'] = ('alpha-ketoglutarate', 'succinyl-CoA')
        self.enzymes['succinyl-CoA synthetase'] = ('succinyl-CoA', 'succinate')
        self.enzymes['succinate dehydrogenase'] = ('succinate', 'fumarate')
        self.enzymes['fumarase'] = ('fumarate', 'malate')
        self.enzymes['malate dehydrogenase'] = ('malate', 'oxaloacetate')

    def randenzyme(self):
        an_enzyme = choice(self.enzymes.keys())
        print "Reaction (enzyme): %s" % an_enzyme
        return an_enzyme

x = TCA()
print 'Enter "1" for a random enzyme or "2" to exit'
choice = raw_input("> ")
if choice == '1':
    x.randenzyme()
elif choice == '2':
    sys.exit()

The error I get is:
Traceback (most recent call last):
File "/Users/sloria1/TCASO.py", line 24, in <module>
x.randenzyme()
File "/Users/sloria1/TCASO.py", line 16, in randenzyme
an_enzyme = choice(self.enzymes.keys())
TypeError: 'str' object is not callable


A: It's impossible to be certain without a traceback, but you probably did something silly like stomp on choice or the like.
