[Tutor] Class error
Andreas Kostyrka
andreas at kostyrka.org
Sun Jun 17 21:53:00 CEST 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Well, Python is not Java :)
Unqualified names reference always only objects defined in the local
module by default.
If you want to use unqualified names, you could do something like that:
from AddrBookEntry import AddrBookEntry
or
import AddrBookEntry as abe
AddrBookEntry = abe.AddrBookEntry
Andreas
Henry Dominik wrote:
> Thanks a million Alan,
>
> Your suggestion helped solve the problem.
> Besides, why did I have to do this: class
> EmplAddrBookEntry(AddrBookEntry.AddrBookEntry):
>
> The AddrBookEntry and EmplAddrBookEntry classes are in the same folder, I
> didn't think I needed to call another module or something..
>
> Well, I need to learn more :)
>
> Thanks anyway
>
> --Dom
> ----- Original Message -----
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> To: <tutor at python.org>
> Sent: Sunday, June 17, 2007 7:28 PM
> Subject: Re: [Tutor] Class error
>
>
>> "Henry Dominik" <fiveholiday55 at hotmail.com> wrote
>>
>>
>>> import AddrBookEntry
>>>
>>> class EmplAddrBookEntry(AddrBookEntry):
>> This says you are creating a new class that inherits
>> from the *module* AddrBookEntry. Notice that the
>> error message referred to the module not the class...
>>
>> You probably meant:
>>
>> class EmplAddrBookEntry(AddrBookEntry.AddrBookEntry):
>>
>>> def __init__(self, nm, ph, id, em):
>>> AddrBookEntry.__init__(self, nm, ph)
>> Which makes this line become
>> AddrBookEntry.AddrBookEntry.__init__(self, nm, ph)
>>
>> HTH,
>>
>> --
>> Alan Gauld
>> Author of the Learn to Program web site
>> http://www.freenetpages.co.uk/hp/alan.gauld
>>
>> _______________________________________________
>> Tutor maillist - Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGdZEbHJdudm4KnO0RAnz9AJ409z7wGgQgQxC2T9u7JQJz8W2h6wCcCFQD
OqhkiSC897klBc1SMZ0rMTc=
=DPIk
-----END PGP SIGNATURE-----
More information about the Tutor
mailing list