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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:49:10+00:00 2026-05-22T19:49:10+00:00

I have defined an object that has several attribute.. class thing(object): def __init__(self, type,

  • 0

I have defined an object that has several attribute..

class thing(object):
    def __init__(self, type, name, attrA, attrB, attrC):
        self.type = type
        self.name = name
        self.attrA = attrA
        self.attrB = attrB
        self.attrC = attrC

lets say then I have a list of things

self.things=[thing('car','fred',1,2,3),
             thing('car','george',a,b,c),
             thing('truck','bob',6,7,8),
             thing('truck','tom',x,y,z)
            ]

I then populate a choice box with SOME of the items from that list

for each in self.things:
    if each.type == 'car':
       self.choiceCar.Append(item=each.name)

When the user selects Bob from the dropdown I have an event for that

def EvtChoice(self,event):
    self.Name = event.GetString()

This captures the name of the selection, but how do I get the other attributes? What I am currently doing is

     for each in self.items:
        if self.Name == each.name
          #Get other things here

My thought is that if my list grows large then this loop through my entire list will become very inefficient and really unneeded since the user has already selected the specific item I want. What I think I should be able to do is to get the index of the selected item, but im not sure how to do that, or even if that is the correct way to go about it.

  • 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-05-22T19:49:11+00:00Added an answer on May 22, 2026 at 7:49 pm

    Associating data or objects with wx.Choice or wx.ComboBox is pretty easy. You can see an example using the latter here:

    http://www.blog.pythonlibrary.org/2010/12/16/wxpython-storing-object-in-combobox-or-listbox-widgets/

    The basic idea is to pass an empty list to the control’s constructor and then iterate over the objects and Append them to the control. So something like this:

    for obj in self.things:
        self.choiceCar.Append(obj.name, obj)
    

    Then in the event handler for the widget, you can get the object back by doing this:

    obj = self.choiceCar.GetClientData(self.choiceCar.GetSelection())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python module that defines a number of classes: class A(object): def
I have the following User.h that holds several attributes (strings). User.cpp has all the
I have a struct defined like follows as part of an object. I'm trying
Suppose I have an array of a objects of user defined class. Wanted to
I have defined an interface in C++, i.e. a class containing only pure virtual
I have an interface that I have defined in C++ which now needs to
I'm reviewing a collegue's code, and I see he has several constants defined in
Given a case where I have an object that may be in one or
I have an @activity that has_many :clientships When creating a new object I assign
I have recently started work on a project that has already been running for

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.