On 14 Jul 2002 at 19:53, M.-A. Lemburg wrote:
Gordon McMillan wrote:
... But stuffing a __path__ attribute into a module does *not* make the module a package.
Hmm, I know that Python itself uses __path__ to tell whether it has a package or not, so I don't see why a module can't be regarded as package.
If you put on a Richard M. Nixon mask, you might be mistaken for ("regarded as") Richard M. Nixon. That doesn't make you Richard M. Nixon. Stuffing __path__ into a module means that *most* of Python's runtime will regard your module as a package. It doesn't make it a package. In particular, most introspection tools and most programmers will not recognize your module as a package.
Moving the module into a directory of the same name and then renaming it to __init__.py has the same effect. And in that case, hacking __path__ is perfectly legal.
Yes, it now *is* a package. One which violates recommended practice, which is to keep __init__.py simple, but still a package.
You haven't commented on the sys.modules trick yet. This one doesn't even use the __path__ hackery :-)
DateTime.py: import sys import mx.DateTime sys.modules[__name__] = mx.DateTime [...] See: it's the same module :-)
Anytime x != sys.modules[x].__name__, someone, sometime will suffer. Installer and (I believe) py2exe have hooks so that this gets analyzed properly. The hook is keyed by "DateTime". If you really find it intolerable to stick your users with making a one line change in their code, you might consider contributing hooks to Installer (or patches to py2exe). Particularly for your non-free packages, since I'm not going to download those and reverse-engineer them. Or perhaps you could do like Pmw, and include a "bundle" script. -- Gordon http://www.mcmillan-inc.com/