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 8762411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:31:32+00:00 2026-06-13T15:31:32+00:00

I am attempting to use a module called interface.py which defines a list of

  • 0

I am attempting to use a module called interface.py which defines a list of conditions and a few functions to check arguments against those conditions. There are many thousands of conditions however, and so I want to use a dictionary instead of a list to prevent needing to look at all of them. To do this I’m using the following code:

def listToDictionary(list):
    """This function takes a list of conditions and converts it to a dictionary
    that uses the name of the condition as a key."""

    d = {}
    for condition in list:
        if condition.name.lower() not in d:
            d[condition.name.lower()] = []
        d[condition.name.lower()].append(condition)
    return d

conditionList = listToDictionary(conditions.list) #the condition list comes from another module

Further into the file are the actual interface functions that take arguments to compare with the list of conditions – these functions are written assuming that conditionList will be a dictionary.

Unfortunately this isn’t working. Giving error details is difficult because this code is being imported by a django page and I am trying to avoid talking about django so this question stays uncomplicated. Essentially the pages including this code will not load, and if I change it back to just using a list everything works fine.

My suspicion is that the problem has to do with how Python treats import statements. I need the listToDictionary conversion to run as soon as interface.py is imported, otherwise the interface functions will expect a dictionary and get a list instead. Is there any way to ensure that this is happening?

  • 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-13T15:31:33+00:00Added an answer on June 13, 2026 at 3:31 pm

    An educated guess: the list in conditions.list is not yet fully constructed when your module is being imported. As a result, you get a dictionary that is missing some entries or even empty, which is causing problems later. Try deferring the construction of the dict, like this:

    conditionTable = None     # shouldn't call it list if it's a dict
    
    def get_cond_table():
        global conditionTable
        if conditionTable is None:
            conditionTable = listToDictionary(conditions.list)
        return conditionTable
    

    Instead of referring to conditionList in your functions, refer to get_cond_table().

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

Sidebar

Related Questions

I'm attempting to use the python subprocess module to log in to a secure
Im attempting to use a C++ extension for Python called PySndObj. and getting an
I am attempting to use the re module in Python 2.7.3 with Unicode encoded
We are attempting to use the paramiko module for creating SSH tunnels on demand
I'm attempting to use the jQuery UI Tabs module, but whenever I attempt to
I'm attempting to use the DotNetCart ecommerce module in a solution we are building.
I'm attempting to use the python logging module to do complex things. I'll leave
I am currently attempting to use a custom module as the first page when
I am attempting to use the 'tempfile' module for manipulating and creating text files.
I'm attempting to use savepoints with the sqlite3 module built into python 2.6. Every

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.