creating new objects with references to them

Steve Holden steve at holdenweb.com
Thu Nov 2 17:33:51 CET 2006


JohnJSal wrote:
> Ant wrote:
> 
> 
>>It all depends on what UI you are using (Web frontend? GUI such as
>>Tkinter?) and what your use case is.
> 
> 
> Making it myself with wxPython.
> 
> 
>>What is it exactly that you want to do? Create a bunch of Researcher
>>objects and then save them in a single hit? Create a list of
>>Researchers and then choose which to save to the db? Populate a list of
>>researchers from the db, and have the option of editing or adding new
>>ones? Should the new Researcher objects be committed to the db as soon
>>as they are saved?
> 
> 
> There are two options: save current record and save all records, both
> of which put the info in the DB immediately.
> 
> 
> 
>>Anyway, a simple list of Researchers should suffice for any of these
>>purposes, and assuming you want to commit them all in one hit, you have
>>a list of objects ready to iterate over.
> 
> 
> Ok, so in making a list does this mean that I won't have a name for
> each instance? I just have to iterate over the list when I need them?
> I'm not sure how I would do this if the user chooses just to save a
> single record and not all of them.
> 
Suppose you have a function dBWrite(r), where r is (some representation 
of) a record you want to write into the database.

Further suppose you currently have 10 records, stored in a list rec, 
with indices 0 through 9.

To write record 7 only you could use

     dbWrite(rec[7])
     conn.commit() # assuming dbWrite uses connection conn
     del rec[7]
     # you'd also want to kill the window containing this record

To write them all you might try

     for r in rec:
         dbWrite(r)
     conn.commit()
     rec = []
     # Close all record windows

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