Message117102
| Author |
ncoghlan |
| Recipients |
belopolsky, eli.bendersky, georg.brandl, ncoghlan, terry.reedy |
| Date |
2010年09月21日.21:26:19 |
| SpamBayes Score |
2.5499457e-07 |
| Marked as misclassified |
No |
| Message-id |
<1285104381.54.0.821834880277.issue9325@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|