Accessing attributes

2007-06-12 Thread Jeff Rollin
Hi there.

I'm working with the Python Tutorial "Byte of Python" at swaroopch.info.

I have created the attached file, but when I execute:

% objvar.py

I get the error message:

(Initializing Calamity Jane)
Traceback (most recent call last):
  File "/home/jef/bin/objvar.py", line 49, in 
Person.how_many()
AttributeError: class Person has no attribute 'how_many'

Where am I going wrong?

Many TIA for any help.

Jeff


objvar.py
Description: application/python
-- 
http://mail.python.org/mailman/listinfo/python-list

Accessing attributes?

2007-06-12 Thread Jeff Rollin
Hi there.

I'm working with the Python Tutorial "Byte of Python" at swaroopch.info.

I have created the following file:


#!/usr/bin/env python
# Filename: objvar.py

class Person:
"""Represents a person."""
population = 0# class variable

def __init__(self,name):
"""Initializes the person's data."""
self.name = name # object variable
print '(Initializing %s)' % self.name

# When this person is created, he/she adds to the population
Person.population += 1

def __del__(self):
"""I am dying."""
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 say_hi(self):
"""Greeting by the person.

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

def how_many(cls):
"""Prints the current population."""
if Person.population == 0:
print 'Nobody is alive as of now.'
elif Person.population == 1:
print 'There is just one person here.'
else:
print 'We have %d persons here.' % Person.population
how_many = classmethod(how_many)

#jeff = Person('Jeff')

#jeff.say_hi()

cj = Person('Calamity Jane')
#cj.say_hi()
Person.how_many()

#jeff.say_hi()
Person.how_many()
-

 but when I execute:

% objvar.py

I get the error message:

(Initializing Calamity Jane)
Traceback (most recent call last):
  File "/home/jef/bin/objvar.py", line 49, in 
    Person.how_many()
AttributeError: class Person has no attribute 'how_many'

Where am I going wrong?

Many TIA for any help.
-- 
http://mail.python.org/mailman/listinfo/python-list

Newsgroup query

2007-06-12 Thread Jeff Rollin
Hi.

You may have just seen that I posted a more-or-less identical message to the
group. This was because the message w/ the attached file didn't show up for
me - but I also just got a reply which references the message with the
attached file.

Why do I not see my messages with attached files in the newsgroup, and is
there any way to configure this?

TIA.

Jeff
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing attributes

2007-06-12 Thread Jeff Rollin
In the last episode, on Tuesday 26 Sivan 5767 11:09, Marc Christiansen
wrote:


> 
> The indentation of __del__, say_hi and how_many is wrong. You define
> them inside __init__. Move them to the same indentation level as
> __init__ and all should work.

Thanks very much.

Jeff
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newsgroup query

2007-06-12 Thread Jeff Rollin
In the last episode, on Tuesday 26 Sivan 5767 11:21, Marc 'BlackJack'
Rintsch wrote:

> In <[EMAIL PROTECTED]>, Jeff Rollin wrote:
> 
>> Why do I not see my messages with attached files in the newsgroup, and is
>> there any way to configure this?
> 
> No, most news servers strip attachments from postings in non-binary
> groups.  It's a plain text medium.
> 
> Ciao,
> Marc 'BlackJack' Rintsch

OK, I'll keep that in mind.

TVM.

Jeff
-- 
http://mail.python.org/mailman/listinfo/python-list