__del__<br><br>I use it to close a mysql connection<br><br clear="all">-Alex Goretoy<br><a href="http://www.goretoy.com">http://www.goretoy.com</a><br><br>E. B. White  - "Be obscure clearly."
<br><br><div class="gmail_quote">On Mon, Mar 16, 2009 at 10:11 PM, <a href="mailto:thomas.hansen@gmail.com">thomas.hansen@gmail.com</a> <span dir="ltr"><<a href="mailto:thomas.hansen@gmail.com">thomas.hansen@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi all,<br>
<br>
We've been breaking our heads over a good way of accomplishing an<br>
"on_load" event in our multitouch GUI frameowork PyMT.  We think we'd<br>
like to trigger an "on_load" event after a class is fully instantiated<br>
(or just a function call for simplicity, so you dont need to worry<br>
about our specific system).  This is so that if I make a subclass of<br>
some widget, I dont have to overwrite the __init__ method (use super,<br>
know the args, and pass them) everytime.  Maybe I just want to do some<br>
really basic stuff that doesn't really have anything to do with the<br>
parent class.<br>
<br>
Anyway.  My first attempt was to simply put a call to self.on_load at<br>
the end of the widget base class.  This doesn't work though, because,<br>
if I subclass it and do things after the call to super.__init__,<br>
on_load will be called before the constructor finishes (when the top<br>
most parent class __init__ finishes)<br>
<br>
We've sort of managed to achieve this by using a decorator that<br>
changes the __init__ function.  but even this doesnt seem like the<br>
best way to do this.  a) I now have to decorate every constructor i<br>
ever write. b) it seems impossible to make it so that it only happens<br>
once after the object is actually instantiated (since i have a<br>
decorator on all my constructors..each constructor in the inheritance<br>
line will call on_load once)<br>
<br>
Can I do something fancy with metaclasses here?  I think I could kind<br>
of do this by making all my classes use __new__, and then essentially<br>
use __init__ as what i want on_load to be...but that just seems really<br>
nasty and unpythonic.  not to speak about the confusion it would cause<br>
with people trying to figure out the library.<br>
<br>
So any ideas on how to get a function called on an object just after<br>
__init__ is done executing?<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>