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

Denis Kasak denis.kasak at gmail.com
Tue Mar 3 13:16:59 EST 2009


On Tue, Mar 3, 2009 at 6:13 AM, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Mon, 2 Mar 2009 16:56:58 -0800 (PST), Nick Mellor
> <nick.mellor.groups at pobox.com> declaimed the following in
>>
>>     def __init(self):
>>         self.forename = RandomName("h:\\Testing\\NameDb\
>> \Forenames.csv", namefield = "Forename")
>
>        Where is "RandomName" defined? Python is case sensitive, and the
> method further down is "randomName".

You could ask the same for dictfile(), which is also not shown, though
you could probably deduce from the filename (and the fact that it
works now) that it is defined elsewhere in the same file.

>        Furthermore, given the indentation you show, randomName is a method
> of RandomPerson... If that is true, you'll need to do
>
>                target = self.randomName(...)
>
>>         self.surname = RandomName("h:\\Testing\\NameDb\\Surnames.csv",
>> namefield = "Surname")
>>         self.randomAddress = dictfile("h:\\Testing\\NameDb\
>> \Addresses.csv").cycleShuffled() it should be obvious
>> [...]
>>
>>     def randomName(self):

As the OP said, RandomName is a class and, judging by the
capitalization, he is instantiating objects of the said class and not
the method of RandomPerson.

>        Up above you are pass two arguments (besides the "self" with my
> noted change would supply), but here you do not have anything to accept
> them... Where is that file name and that keyword argument supposed to be
> received?
>
>        def randomName(self, fileid, namefield):
>        #have to use "namefield" as you used a keyword passing mechanism
>
>>         return {"Forename" : self.forename.randomByWeight(),
>>                 "Surname" : self.surname.randomByWeight()}
>>
>        This will return a dictionary containing both forename and
> surname... Assuming you have forename and surname OBJECTS with contain a
> randomByWeight method.

In all probability, forename and surname *are* instances of RandomName
and contain the randomByWeight() method.

-- 
Denis Kasak



More information about the Python-list mailing list