[Tutor] assert

python-tutor@toddmaynard.com python-tutor at toddmaynard.com
Fri Dec 23 20:00:02 CET 2005


Shivayogi,

Sorry my last e-mail wasn't very helpful.  

Better would have been:

>>> a=myClass()
>>> b=myClass()
>>> a.howmany()
>>> myClass.count=0
>>> del a
which will (hopefully)  give you something like: 

Exception exceptions.AssertionError: <exceptions.AssertionError instance at 
0xb7b1d12c> in <bound method myClass.__del__ of <__main__.myClass instance at 
0xb7b1d2ec>> ignored

Assert is commonly used as a sanity check for things that you always expect to 
be true.

Hope this helps,

Todd Maynard


On Friday 23 December 2005 06:55, python-tutor at toddmaynard.com wrote:
> Try this:
> >>>a=myClass()
> >>>b=myClass()
> >>>a.howmany()
> >>>a.count=0
> >>>del a
>
> Does this help clear things up?
>
>
> Todd Maynard
>
> On Friday 23 December 2005 06:18, shivayogi kumbar wrote:
> > class myClass:
> >                         count = 0
> >                          def __init__(self):
> >                                   myClass.count = myClass.count + 1
> >                           def __del__(self):
> >                                    myClass.count =myClass.count -1
> >                                     assert myClass.count>0
> >                           def howmany(self):
> >                                    return myClass.count
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list