Attribute error-- but I'm innocent(?)
Chris Rebert
clp2 at rebertia.com
Mon Mar 2 20:03:02 EST 2009
On Mon, Mar 2, 2009 at 4:56 PM, Nick Mellor
<nick.mellor.groups at pobox.com> 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\dictfile.py", 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.
Cheers,
Chris
--
Shameless self-promotion:
http://blog.rebertia.com
More information about the Python-list
mailing list