Embedding: Defining packages?

Michael P. Reilly arcege at shore.net
Thu Jul 22 21:07:44 EDT 1999


Bjoern Giesler <un4e at rz.uni-karlsruhe.de> wrote:
: Hi,

: Michael P. Reilly <arcege at shore.net> wrote:
: : Bjoern Giesler <un4e at rz.uni-karlsruhe.de> wrote:
: : : theModule = Py_InitModule(methodDefs, "MyProgram.Server.Communications");

: : theModule = Py_InitModule("MyProgram.Server.Communications", methodDefs);

: ...was of course what I meant. Mine was just a typo. Still, this gives me a
: module named "MyProgram.Server.Communications", but _no_ module "MyProgram".
: What I want is to be able to say
: 	from MyProgram import *
: and then address functions via
: 	Server.Communications.foo()

: This doesn't work; it seems that Python can't define _packages_ from C, but
: only _modules_. Is that correct?

Yes, I see what you mean now; sorry.  Correct, you cannot create
"package modules" that can be imported through "from", but you can
create the naming conventions.  Most of the reason is how the importer
works, it is looking for a file with the submodule name, not a module
with that dotted name.  You would have to install a replacement for the
__builtin__.__import__ function.

  -Arcege





More information about the Python-list mailing list