[EMAIL PROTECTED] wrote:
> Nate,
> That's exactly what I came up with. We were just wondering if that was the
> only way to do it.
>
> What's cool about this is I can refer to the object by doing the
> following...
>
> for i in range(1, 10):
> exec("o=self.biz%s = dabo.biz.dBizObj()" % i)
> o.CurrentSql=....
> o.do_something_else
>
> Thanks
> Larry Long
>
> p.s If I executed the code above, does
> o=None
> Release the bizobj? I don't think it does. if not, then how can I release
> it?
Objects in Python are released by the garbage collector when there are
no more references to them from anywhere. So whether you use the exec()
or setattr() method (but you should use setattr) the bizobjs you create
in that loop will stay alive as long as o is in scope (just the single
iteration in the for loop) and as long as the object referred to as
'self' is alive, if you never delete the reference from self using e.g.
delattr().
So your short answer is: no, calling o=None will not release the bizobj
(because self has a reference to it).
The longer answer requires asking more questions:
+ If you don't want to keep the bizobj around, why bother attaching it
to self? IOW:
for i in range(10):
o = dabo.biz.dBizobj()
o.UserSQL = ...
Now the bizobj goes out of scope after the iteration.
+ You probably do want to keep the bizobj around, so that makes me
wonder why you asked about setting o=None to release it, when o is only
active inside the for loop.
But, here's how to release the bizobj based on what I know about what
you are doing:
for i in range(1, 10):
name_of_biz_to_delete = "biz%s" % i
delattr(self, name_of_biz_to_delete)
This will work if you haven't saved a reference to that bizobj in any
other object.
--
pkm ~ http://paulmcnett.com
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/dabo-users/[EMAIL PROTECTED]