refering to base classes
Chaz Ginger
cginboston at hotmail.com
Wed Aug 30 07:01:11 EDT 2006
glenn wrote:
>> Shouldn't that be
>>
>> beagle = animal.dog()
>>
>> to create an instance?
>>
>> We've all done it ...
> lol - actually Im confused about this - there seem to be cases where
> instantiaing with:
> instance=module.classname()
> gives me an error, but
> instance=module.classname
> doesnt - so I got into that habit, except for where I had a constructor
> with parameters - except now Im feeling foolish because I cant
> replicate the error - which suggests I didnt understand the error
> message properly in the first place... arrgh
> I guess thats just part of the process of gaining a new language.
>
> glenn
>
module.classname and module.classname() are two different things. If you
use module.classname() you invoke the __new__ and __init__ methods in
the class, and you might get an error from them.
On the other hand module.classname will always work, assuming classname
really exists in module. What you get back is a sort of reference to the
class itself and not an instance of it.
More information about the Python-list
mailing list