| | |
weird exceptions:(
Thread Solved
![]() |
•
•
Join Date: Aug 2005
Posts: 148
Reputation:
Solved Threads: 6
Hello, I'm trying to execute this simple code:
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...
Python Syntax (Toggle Plain Text)
class Person: population = 0 def __init__(self, name): print 'Creating % s peron' % name self.name = name Person.population += 1 def __del__(self): print 'Destroying %s person' % self.name Person.population -= 1 prvi = Person('Asimi') drugi = Person('Mici')
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...
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:
If so, please include them, because the other code worked fine for me.
Python Syntax (Toggle Plain Text)
del drugi del prvi
Vi veri veniversum vivus vici
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.
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.
May 'the Google' be with you!
![]() |
Similar Threads
- Something weird... (Monitors, Displays and Video Cards)
- Weird segfault involving popen (C)
- Exceptions (Java)
- WEIRD! php pages do not load unless i hit refresh (PHP)
- Arithmetic Exceptions and exception-handling statements (Java)
- Games act weird (Troubleshooting Dead Machines)
- weird problem : Internet Explorer cannot load all geocities pages (Windows NT / 2000 / XP)
Other Threads in the Python Forum
- Previous Thread: Plotting math functions (Python)
- Next Thread: nice online book with examples
| Thread Tools | Search this Thread |
abrupt alarm ansi anti apache approximation array assignment backend beginner binary bluetooth builtin calculator character cmd converter countpasswordentry curved customdialog cx-freeze dan08 data decimals dictionary directory exe file float format function gnu halp heads homework http ideas inches input itunes java leftmouse library line lines linux list lists loop module mouse mysqlquery number numbers numeric output parsing path phonebook pointer prime programming push py2exe pygame python random recursion redirect schedule screensaverloopinactive script scrolledtext software sqlite ssh statictext statistics string strings sudokusolver terminal text thread time tlapse tuple twoup ubuntu unicode urllib urllib2 variable ventrilo webservice wikipedia wordgame write wxpython xlib






