![]() |
| ||
| weird exceptions :( Hello, I'm trying to execute this simple code: class Person: I'm using Wing IDE trial and here's what is output in debug mode: Creating Asimi peron Creating Mici peron Destroying Mici person Exception exceptions.AttributeError: "'NoneType' object has no attribute 'population'" in <bound method Person.__del__ of <__main__.Person instance at 0x00B29558>> ignored Destroying Asimi person Exception exceptions.AttributeError: "'NoneType' object has no attribute 'population'" in <bound method Person.__del__ of <__main__.Person instance at 0x00B29530>> ignored Problem is solved by putting self.population - = 1 in __del__ method, but the example is from book ByteOfPython and population is supposed to be class variable... I really don't have a clue what is wrong here... |
| ||
| Re: weird exceptions:( It looks like you haven't included all the code you wrote to test this. Were there statements after 'drugi = Person('Mici')'? Statements like, perhaps: del drugiIf so, please include them, because the other code worked fine for me. |
| ||
| Re: weird exceptions:( Look at variable k in the code snippet at: http://www.daniweb.com/code/snippet354.html This is a similar situation, it is declared outside of the class methods and needs self to bring it into the methods. The class name won't do. If your book uses this, then it is wrong (can happen). Maybe very early versions of Python allowed this. Remember, special method __init__() is called first and acts as constructor. Special method __del__() acts as the mostly optional destructor. |
| All times are GMT -4. The time now is 6:56 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC