python newbie

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Nov 3 10:42:13 EDT 2007


En Sat, 03 Nov 2007 09:55:38 -0300, Paul Rubin  
<"http://phr.cx"@NOSPAM.invalid> escribió:

> Duncan Booth <duncan.booth at invalid.invalid> writes:
>> modules are not special in any way, except that you cannot subclass  
>> them.
>> Oops, sorry I got that wrong. Modules are not special in any way, they  
>> can
>> have methods as well as functions:
>
> I've felt for a long time that you should be able to define __call__
> on a module, but that doesn't seem to be allowed, at least if you
> try it in the obvious way.

Notice that you usually define __call__ for a *type*, not for specific  
object instances. All special methods, like __call__, are searched on the  
type - not on the instance. And all modules are instances of the same type.
For something like that to work, each module should be a *subclass* of  
moduletype, not an instance.

-- 
Gabriel Genellina




More information about the Python-list mailing list