Attribute error-- but I'm innocent(?)

Chris Rebert clp2 at
Tue Mar 3 02:03:02 CET 2009

On Mon, Mar 2, 2009 at 4:56 PM, Nick Mellor
<nick.mellor.groups at> wrote:
> Hi all,
> I'm pretty sure I'm following all the Python rules: I've put "self"
> before "forename" to make sure it's treated as a data attribute
> (instance variable.) And from within a class, I'm told, you need to
> prefix the var with self too. RandomName is a class that I've tested
> (and which still works.) So why do I get this error?
>  File "h:\Testing\NameDb\", line 107, in randomName
>    return {"Forename" : self.forename.randomByWeight(),
> AttributeError: RandomPerson instance has no attribute 'forename'
> Here's the code (Python 2.6, PythonWin):
> class RandomPerson:
>    def __init(self):

That previous line is supposed to be:
   def __init__(self):

Note the trailing underscores.


Shameless self-promotion:

More information about the Python-list mailing list