multiple namespaces within a single module?
__peter__ at web.de
Fri Feb 10 06:10:33 EST 2012
> Hi Peter
> On Feb 9, 7:33 pm, Peter Otten <__pete... at web.de> wrote:
>> jkn wrote:
>> > is it possible to have multiple namespaces within a single python
>> > module?
>> Unless you are abusing classes I don't think so.
>> > I have a small app which is in three or four .py files. For various
>> > reasons I would like to (perhaps optionally) combine these into one
>> > file.
>> Rename your main script into __main__.py, put it into a zip file together
>> with the other modules and run that.
> Hmm ... thanks for mentioning this feature, I didn't know of it
> before. Sounds great, except that I gather it needs Python >2.5? I'm
> stuck with v2.4 at the moment unfortunately...
You can import and run explicitly,
$ PYTHONPATH mylib.zip python -c'import mainmod; mainmod.main()'
assuming you have a module mainmod.py containing a function main() in
More information about the Python-list