This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: particular variable's name case exception attributeError
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, mark.dickinson, r.david.murray, tq0fqeu
Priority: low Keywords:

Created on 2009-07-16 08:46 by tq0fqeu, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
objvar.py tq0fqeu, 2009-07-16 08:46 the Person class file
Messages (4)
msg90564 - (view) Author: tq0fqeu (tq0fqeu) Date: 2009-07-16 08:46
To create a instance of Class Person
[code]
rosss = Person('ross')
rosss.sayHi()
rosss.howMany()
[/code]
It's OK

But
[code]
ross = Person('ross')
ross.sayHi()
ross.howMany()
[/code]
It has exception, get that:
Exception AttributeError: "'NoneType' object has no attribute
'population'" in <bound method Person.__del__ of <__main__.Person
instance at 0xb7e0b34c>> ignored

python 2.6.2 + gcc 4.3.3 + kernel 2.6.28-13-generic
msg90565 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-07-16 10:00
You examples both work for me.  Please go to python-list or python-tutor
for help debugging your code.  In particular you need to learn more
about __del__ and why you probably don't want to be using it.

rdmurray@maestro:~/python/trunk>./python  
Python 2.7a0 (trunk:74008, Jul 14 2009, 20:56:15) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from objvar import Person
>>> rosss = Person('ross')
(Initializing ross)
>>> rosss.sayHi()
Hi, my name is ross.
>>> rosss.howMany()
I am the only person here.
>>> ross = Person('ross')
(Initializing ross)
>>> ross.sayHi()
Hi, my name is ross.
>>> ross.howMany()
We have 2 persons here.
msg90566 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-07-16 10:46
This has to do with the order that things are deleted/cleaned-up on 
interpreter shutdown.  In the reported case, it just happens that the 
'Person' entry in the globals() dict is deleted *before* __del__ is called 
on the last Person instance, causing problems for the lookup of 'Person' 
that's involved in the line 'Person.population -= 1'.

I wonder whether the output from these 'ignored' exceptions on interpreter 
shutdown could be suppressed entirely, at least for non-debug builds?
msg90567 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-07-16 11:22
Well, "Errors should never pass silently."
In this case, it is possible to replace "Person.population" by
"self.__class__.population".

This said, it could be interesting to cleanup modules in a more
predictive way, for example in the reverse order of their import order.
History
Date User Action Args
2022-04-11 14:56:51adminsetgithub: 50744
2009-07-16 11:22:05amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg90567
2009-07-16 10:46:34mark.dickinsonsetnosy: + mark.dickinson
messages: + msg90566
2009-07-16 10:00:08r.david.murraysetstatus: open -> closed
priority: low
type: compile error -> behavior

components: + Interpreter Core

nosy: + r.david.murray
messages: + msg90565
resolution: works for me
stage: resolved
2009-07-16 08:46:10tq0fqeucreate