module with __call__ defined is not callable?

limodou limodou at gmail.com
Tue Feb 7 21:51:46 EST 2006


On 2/8/06, adam johnson <adam.sven.johnson at gmail.com> wrote:
> Hi All.
> I was wondering why defining a __call__ attribute for a module doesn't make
> it actually callable.
>
> I don't have any reason for doing so, I was just wondering if it worked, and
> found out it didn't.
>
> $ cat mod.py
> """
> Test callable module
> """
> def __call__():
>     return "in mod.__call__"
>
>
> >>> import mod
> >>> mod()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: 'module' object is not callable
> >>> mod.__call__()
> 'in mod.__call__'
>
>
> Thanks for any replies, Adam.
>
>

I remebered that __call__() is just used for class, but not module. Am I wrong?

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit



More information about the Python-list mailing list