[Tutor] Clueless
Marilyn Davis
marilyn at deliberate.com
Sun Mar 14 03:27:03 EST 2004
On Sat, 13 Mar 2004, Rich Krauter wrote:
> On Sat, 2004-03-13 at 20:44, Marilyn Davis wrote:
> > I can't even give this one a good subject line, I'm so clueless.
> >
> > I'm trying to make something meaningful using __getattribute__.
> > What a bear to stop all the infinite loops!
> >
> > But, finally, I have all that under control.
> >
> > So, my classes are:
> >
> > Logger object
> > /|\ /|\ /|\
> > | | |
> > Watched -------------------- |
> > /|\ list
> > | /|\
> > | |
> > WatchedList ---------------------
> >
> > All is cool as long as I don't implement Logger.__del__
> >
> > But if I do, crash-city when an object goes away:
> >
> > Exception exceptions.AttributeError: "'NoneType' object has no
> > attribute 'close'" in <bound method WatchedList.__del__ of []> ignored
> >
> > If anyone has time and inclination, could you help?
> >
> > Thank you so much.
> >
> > Marilyn Davis
> >
> > #!/usr/bin/env python2.2
> > '''New style classes have __getattribute__ which intercept
> > all references to attributes, ones that exist and don't
> > exist. We'll make a Watched class that logs all accesses and
> > assignments.'''
> >
> > import time
> >
> > class Logger:
> > def __init__(self, name):
> > self.file = open(name, 'w')
> > def logit(self, entry):
> > self.file.write(time.ctime(time.time()))
> > self.file.write('\n' + entry + '\n')
> > self.file.flush()
> > # def __del__(self):
> > # self.file.close()
> >
>
> Hi Marilyn,
>
> I added this to the Watched class, and it seemed to help:
>
> def __del__(self):
> Logger.__del__(self.log)
Did you do anything else? I still get the same crash. You don't?
What version of python?
>
> Also, I wouldn't use 'file' as an attribute name. It's in synonym for
> 'open'.
I didn't know that.
Thank you. I changed that too.
But I'm still stumped.
Thank you for beating your head against this too.
Marilyn
>
> Hope that helps.
>
> Rich
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
--
More information about the Tutor
mailing list