In article <4a3f0ca7-fef0-4f9c-b265-5370e61ed...@d8g2000yqf.googlegroups.com>, moerchendiser2k3 <googler.1.webmas...@spamgourmet.com> wrote: >Aahz: >> >>Set sys.path to include each script's base dir before running it, then >>restore after each script. > >That works, but doesnt solve the problem. > >ScriptA.py has a module in its directory called 'bar.py' >ScriptB.py has a module in its directory called 'bar.py' > >Imagine the 'bar.py' modules dont have the same content, so they are >not equal. > >Now when the first bar.py is imported, the second import for a "import >bar" imports the first one, because its already stored in sys.modules.
Good point, you'll need to save/restore sys.modules, too. That gets you 90-95% of complete namespace separation; if you need more than that, your best bet is to use separate processes. Full-blown namepace isolation is a *hard* problem, just look at all the past attempts to create secure Python (and what you're trying to do is roughly equivalent). -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra -- http://mail.python.org/mailman/listinfo/python-list