creating new objects with references to them
Steve Holden
steve at holdenweb.com
Thu Nov 2 12:59:48 EST 2006
JohnJSal wrote:
> JohnJSal wrote:
>
>
>>Hope that makes sense. It seems like such a common task.
>
>
> Ok, I'm thinking about the suggestion to make a list, but I'm still
> confused. Even with a list, how do I access each instance. Would I have
> to do it by index? I assume I'd do something like this:
>
> self.records = [] # list for storing instances
>
> Then when "New Record" is clicked:
>
> def OnNewRecord(self, event):
> self.records.append(Researchers())
>
> But now what? There is still no reference to that instance? The only
> thing I can think of is that each record will be a tab in a wxPython
> notebook control, and each tab can be referenced by index. So whichever
> tab I'm on, I can use that index to get that particular instance in the
> list.
>
> But this solution seems too tied to my particular implementation. How
> would you normally access these instances in the list?
>
> Let's say there are three objects in the list. Someone fills out the
> text fields for the second one and clicks "Save". I know how to read
> all the information in the fields, but how do I then associate it with
> that second instance?
>
> (Or I wonder if I really even need to, since upon saving, the
> information gets stored in the database immediately. Maybe I don't even
> need a Researcher class at all.)
>
How about having a list of tuples: (record, window). Each window has to
"know" which item it's editing.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list