title: AttributeError when checking if a key exist in a dictionary, using python
body: <p>I am using Python 2.7.2+, and when trying to see if a dictionary holds a given string value (named func) I get this exception:</p>
  
  <pre><code>Traceback (most recent call last):
    File "Translator.py", line 125, in &lt;module&gt;
      elif type == Parser.C_ARITHMETIC : parseFunc()
    File "Translator.py", line 95, in parseFunc
      if unary.has_key(func) : 
  AttributeError: 'function' object has no attribute 'has_key'
  </code></pre>
  
  <p>This is where I define the dictionaries:</p>
  
  <pre><code>binary = {"add":'+', "sub":'-', "and":'&amp;', "or":'|'}
  relational = {"eq":"JEQ" , "lt":"JLT", "gt":"JGT"}
  unary = {"neg":'-'}
  </code></pre>
  
  <p>Here's the function where the exception is raised:</p>
  
  <pre><code>def parseFunc():
      func = parser.arg1 
      print func  
      output.write("//pop to var1" + endLine)
      pop(var1)
      if unary.has_key(func) : // LINE 95
          unary()
          return
      output.write("//pop to var2" + endLine)
      pop(var2)
      result = "//"+func + endLine
      result += "@" + var1 + endLine
      result += "D=M" + endLine
      result += "@" + var2 + endLine
      output.write(result)
      if binary.has_key(func) : 
          binary()
      else : relational()
  </code></pre>
  
  <p>Also, I tried changing <code>if unary.has_key(func)</code> to <code>if func in unary</code> but then I got</p>
  
  <pre><code>Traceback (most recent call last):
    File "Translator.py", line 126, in &lt;module&gt;
      elif type == Parser.C_ARITHMETIC : parseFunc()
    File "Translator.py", line 95, in parseFunc
      if func in unary:
  TypeError: argument of type 'function' is not iterable
  </code></pre>
  
  <p>P.s I tired it also using python 3.2</p>
  
  <p>Any ideas? Thanks</p>