Actually, the parethesis mean "calling" the object.

"Callable" objects can be of different types :
-functions - in which case they get executed
-classes (or metaclasses) - in which case they get "instantiated" (with all the protocol : __new__(), __init__()...) -other objects - in which case they must contain a __call__ method with will be executed when we use the parenthesis operator on the object.

But a module is none of these : when you write "mymodule()", python doesn't have a clue what he must execute/instantiate.

Moduels aren't callable, but they can be "imported", simply by doing "import mymodule", or "import mypackage.mymodule" Note that when you use packages, the modules that the package really contains are searched with a protocol that can be rather elaborate, at least (if I remember) the submodule name must be in the __all__ attribute of the package (i.e, the __all__ array defiend in the package __init__.py file).

I hope I haven't made you more confused with these quick explanations :p


Regards,
pascal

Dale Amon a écrit :
I am trying to get to the heart of what it is I am
missing. Is it the case that if you have a module C in a package A:

        A.C

that there is no way to load it such that you can use:

        x = A.C()

in your code? This is just a simpler case of what I'm
trying to do now, which has a module C in a sub-package
to be imported:

        A.B.C

ie with files:
        mydir/A/B/C.py
        mydir/mymain.py

and executed in mymain.py as:

        x = A.B.C()

I may still chose to do it the way you suggested, but I
would still like to understand why this does not work.

------------------------------------------------------------------------

--
http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to