473,326 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Can someone explain what I've done wrong...

Hi,

I'm following a tutorial about classes, and have created the following
(well, copied it from the manual buy added my own and wifes names)...

class Person:
population=0

def __init__(self,name):
self.name=name
print '(Initialising %s)' % self.name
Person.population += 1

def __del__(self):
print "%s says bye." % self.name

Person.population -= 1

if Person.population == 0:
print "I am the last one"
else:
print "There are still %d people left." % Person.population

def sayHi(self):
'''Greeting by the person.

That's all it does.'''
print "Hi, my name is %s" % self.name

def howMany(self):
if Person.population==1:
print "I am on the only person here."
else:
print "We have %d persons here." % Person.population

Jason=Person("Jason")
Jason.sayHi()
Jason.howMany()

Sophie=Person("Sophie")
Sophie.sayHi()
Sophie.howMany()

Jason.sayHi()

The code, when run, should produce the following...

Hi, my name is Jason.
I am the only person here.
(Initializing Sophie)
Hi, my name is Sophie.
We have 2 persons here.
Hi, my name is Jason.
We have 2 persons here.
Jason says bye.
There are still 1 people left.
Sophie says bye.
I am the last one.

But what I actually get is...

(Initialising Jason)
Hi, my name is Jason
I am on the only person here.
(Initialising Sophie)
Hi, my name is Sophie
We have 2 persons here.
Hi, my name is Jason
We have 2 persons here.
Jason says bye.
There are still 1 people left.
Sophie says bye.
Exception exceptions.AttributeError: "'NoneType' object has no attribute
'popula
tion'" in <bound method Person.__del__ of <__main__.Person instance at
0x0097B53
0>> ignored

I've looked through the code but can't find anything obvious.

I also want to apologise if this isn't the write newsgroup to post on,
but it's the only one I know of. IF anyone knows a good newsgroup, I'd
appreciate it.

TIA

Sep 18 '05 #1
0 694

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Maciej Nadolski | last post by:
Hi! I can`t understand what php wants from me:( So: Cannot send session cache limiter - headers already sent (output started at /home/krecik/public_html/silnik.php:208) in...
8
by: Peter Foti | last post by:
I'm working on a site and the client said he thinks "the main title should be around 28pt and the subtitle probably 18pt". I know pt's are bad, and I want to convince him that he should NOT be...
3
by: MarcJessome | last post by:
Hi, I was wondering if someone could help me through learning C++. I've tried learning before, but I find I would work better if I had someone that could help explain a few things to me. Im using...
10
by: Greg Stark | last post by:
This query is odd, it seems to be taking over a second according to my log_duration logs and according to psql's \timing numbers. However explain analyze says it's running in about a third of a...
5
by: J Allen Horner | last post by:
I'm just starting to learn C, and the tutorial I'm reading uses this code as an example: ----------- #include <stdio.h> #define MAX 10 int a; int rand_seed=10;
20
by: nicolas.riesch | last post by:
I try to understand strict aliasing rules that are in the C Standard. As gcc applies these rules by default, I just want to be sure to understand fully this issue. For questions (1), (2) and...
118
by: 63q2o4i02 | last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning Python the past few months and like it very much. A few years ago I had an AI class where we had to use Lisp, and I absolutely...
16
by: SirG | last post by:
I'm looking for an explanation of why one piece of code works and another does not. I have to warn you that this is the first piece of Javascript I've ever written, so if there is a better way or a...
6
by: Dave Young | last post by:
I'm looking at some code that i've inherited and I'm not really familar with what's going on here and was hoping somone could explain it to me. For reference: f1 is a long f2 is a long ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.