multiple namespaces within a single module?

Peter Otten __peter__ at
Fri Feb 10 06:10:33 EST 2012

jkn wrote:

> Hi Peter
> On Feb 9, 7:33 pm, Peter Otten <__pete... at> 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, 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 python -c'import mainmod; mainmod.main()'

assuming you have a module containing a function main() in

More information about the Python-list mailing list