Although I have never done so, I believe you can also store/manipulate
objects in a database.

Has anyone ever worked this option?


Thank you,
Andrew Robert
Systems Architect
Information Technology - OpenVMS
Massachusetts Financial Services
Phone:  617-954-5882
Pager:   781-764-7321
E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Kent Johnson
Sent: Friday, December 03, 2004 7:42 AM
To: Python Tutor
Subject: Re: [Tutor] Creating & Handling lots of objects

If you want to be able to access the objects by name, you can put them
in a dict. For example,
MyObjects={}
l=["a","b","c"]
for i in l:
        MyObjects[i] = MyClass(i)

Then you can refer to MyObjects["a"]

If all the operations on the objects are done to all objects in a batch,
putting them in a list 
might work. Then you can use list iteration to access all of them:
MyObjects=[]
l=["a","b","c"]
for i in l:
        MyObjects.add(MyClass(i))

then to process all the objects:
for myObj in MyObjects:
     # do something with myObj

Kent


Matt Williams wrote:
> Dear Tutor-list,
> 
> I'm sorry for this appallingly dumb question, but I'm having a little
> problem with objects.
> 
> I've written a class, with some methods. I then want to be able to
call
> the class repeatedly, to create some objects. The number of objects,
and
> some of their initialisation parameters need to be specified later
(i.e.
> at run-time).
> 
> When I generate all these objects, how do I keep track of them. For a
> finite (and small) number I can do this:
> 
> a=MyClass("a")
> b=MyClass("b")
> 
> but this is obviously not scaleable. If I use a list, I can do:
> 
> MyObjects=[]
> l=["a","b","c"]
> for i in l:
>       MyObjects.add(MyClass(i))
> 
> but then I have to search the list (MyObjects) for the object where
> Object.name="a".
> 
> The only other option seems to be finding objects via their hash
codes,
> which I'm sure isn't right
> 
> I'd like to be able to automate something closer to the a=MyClass("a")
> but don't know how to do it....It may be that I'm trying to do it very
> badly, which is Python seems to make it hard for me.
> 
> Thanks,
> 
> Matt
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/tutor
> 
_______________________________________________
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


"MFS Relay Service" made the following
 annotations on 12/03/2004 08:05:23 AM
------------------------------------------------------------------------------
This email communication and any attachments may contain proprietary, 
confidential, or privileged information.  If you are not the intended 
recipient, you are hereby notified that you have received this email in error 
and that any review, disclosure, dissemination, distribution or copying of it 
or its contents is prohibited.  The sender does not waive confidentiality or 
any privilege by mistransmission.  If you have received this email in error, 
please notify the sender immediately, delete this email, and destroy all copies 
and any attachments.
==============================================================================

_______________________________________________
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to