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

  • Home
  • SEARCH
  • 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 7932509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:02:41+00:00 2026-06-03T21:02:41+00:00

I have a program that compares two classes in a series of tests. The

  • 0

I have a program that compares two classes in a series of tests.

The main program (called initial.py) assigns both values to a dictionary

import testcheck

values = {}
valueChange = False

if __name__ == "__main__":
    values['valueOne'] = testcheck.assignValue()       #see note 1
    values['valueTwo'] = testcheck.assignValueTwo()    
    testcheck.checkValues()                            #see note 2

    while valueChange is True :
        values['valueTwo'] =   testcheck.assignValueTwo()
        testcheck.checkValues()

Note 1: both of these return the same class but with different values

Note 2: compares the two classes. after a series of tests, valueChange is set to True, and one value is to be deleted using this code

import initial

...

if initial.valueChange is True:
   del initial.values['valueTwo']

...

This returns the error

del initial.values['valueTwo']
KeyError: 'valueTwo'

I thought it was because adding valueOne and valueTwo would be adding it in the local scope, but even with global values it doesn’t fix it. How would I go about solving this?

  • 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-03T21:02:43+00:00Added an answer on June 3, 2026 at 9:02 pm

    This appears to be a design issue. You seem to be setting up circular imports, which should be avoided if possible. If what you are after is to share a global state across modules of your package, you might want to make use of storing the state within your testcheck module, and not in a global variable of your initial.py

    testcheck.py

    # module globals
    _TEST_VALUES = {}
    valueChanged = False
    
    ...
    
    def getTestValue(name):
        return _TEST_VALUES.get('name', None)
    
    def assignValue():
        # do stuff
        result = 'foo'
        _TEST_VALUES['valueOne'] = result
        return result
    
    def assignValueTwo():
        # do stuff
        result = 'bar'
        _TEST_VALUES['valueOne'] = result
        return result
    
    ...
    

    initial.py

    testcheck.assignValue()     
    testcheck.assignValueTwo()    
    testcheck.checkValues()                          
    
    while testcheck.valueChange:
        testcheck.assignValueTwo()
        testcheck.checkValues()
    

    otherModule.py

    import testcheck
    
    ...
    
    if testcheck.valueChange:
        try:
            del initial.values['valueTwo']
        except KeyError:
            pass
    
    ...
    

    I have no idea where this whole thing is going in terms of real usage. But maybe this will give you an idea of where to start looking. There is no longer a circular import of other modules importing your intial.py entry point. You are storing all the globals within the testcheck module. This example is very quick and dirty. Its only to illustrate.

    No module should ever try to be accessing data of another module which handles the data within an if __name__ == "__main__" block. Because now you are making the assumption that it will always be used as the entry point (never imported by something else) and you start putting restrictions on your code.

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

Sidebar

Related Questions

I have a program that compares two files. I ran visual studio analysis and
I have a program that compares variables from two structs and sets a bit
I have a Java program running on two computers that are both on the
I have a program that compares files in two folders. I want to detect
I have a program that creates lists and needs any assigned values to be
I have a program that needs two integers to be entered to set up
THIS IS HOMEWORK: I have a program that consists of two winforms and three
I have a program that's running in two different modes. I want to compare
I have a program that takes two files as an argument. The first file
In my program, I have a series of if-else statements that look like so:

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.