Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7811609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:13:42+00:00 2026-06-02T04:13:42+00:00

I am using Python 2.7.2+, and when trying to see if a dictionary holds

  • 0

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:

Traceback (most recent call last):
  File "Translator.py", line 125, in <module>
    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'

This is where I define the dictionaries:

binary = {"add":'+', "sub":'-', "and":'&', "or":'|'}
relational = {"eq":"JEQ" , "lt":"JLT", "gt":"JGT"}
unary = {"neg":'-'}

Here’s the function where the exception is raised:

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()

Also, I tried changing if unary.has_key(func) to if func in unary but then I got

Traceback (most recent call last):
  File "Translator.py", line 126, in <module>
    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

P.s I tired it also using python 3.2

Any ideas? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:13:44+00:00Added an answer on June 2, 2026 at 4:13 am

    In Python 3, dict.has_key() is gone (and it has been deprecated for quite some time). Use x in my_dict instead.

    Your problem is a different one, though. While your definition shows unary should be a dictionary, the traceback shows it actually is a function. So somewhere in the code you did not show, unary is redefined.

    And even if unary was a dictionary, you would not be able to call it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Python 2.5. I'm trying to use this 'with' statement. from __future__ import
I'm trying to create an xml entry that looks like this using python and
Hello i am trying to do a dictionary by using Python, What needs to
I am trying to translate a string using google translate API. #!/usr/bin/env python #
I am trying to encrypt a string using C# and decrypt it using Python.
I am using Python 2.6 and am trying to run a simple random number
I am trying to run a python script using :- python scriptname.py someoptions When
I'm trying to calculate the sunset / rise times using python based on the
I'm trying to convert SVG to PNG using Python, Cairo and librsvg. Everything is
I am trying to plot two columns from a text file using python matplotlib

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.