Message117102
I've thought about this in the past, but never really pursued it due to the question of what to do with the __main__ namespace.
There are three options here:
1. Use runpy.run_module to run the module in a fresh __main__ namespace
2. Use runpy.run_module to run the module under its own name
3. Use runpy._run_module_as_main to run the module in the real __main__ namespace
Option 3 is probably a bad idea (due to the risk of clobbering globals from pdb/trace/profile/doctest/etc) but failing to do it that way creates a difference between the way the actual -m switch works and what these modules will be doing.
That said, I haven't looked closely at what these modules do for ordinary scripts, where much the same problem will already arise. If option 1 is adequate for this purpose, then it shouldn't be that hard to add - it's just that I've never done the investigation to see if it *would* be adequate. |
|
Date |
User |
Action |
Args |
2010-09-21 21:26:21 | ncoghlan | set | recipients:
+ ncoghlan, georg.brandl, terry.reedy, belopolsky, eli.bendersky |
2010-09-21 21:26:21 | ncoghlan | set | messageid: <1285104381.54.0.821834880277.issue9325@psf.upfronthosting.co.za> |
2010-09-21 21:26:19 | ncoghlan | link | issue9325 messages |
2010-09-21 21:26:19 | ncoghlan | create | |
|