[Python-Dev] Running a module as a script

Nick Coghlan ncoghlan at email.com
Fri Oct 1 03:09:02 CEST 2004


Quoting "Phillip J. Eby" <pje at telecommunity.com>:

> Using the C equivalent of 'imp.find_module()' should cover all these cases, 
> and any new forms of PY_SOURCE or PY_COMPILED that come up in future.

That's essentially what the patch does. PyRun_SimpleModuleFlags uses
_PyImport_FindModule to obtain the absolute file location, then uses
PyRun_SimpleFileExFlags to actually run the script.

_PyImport_FindModule is a trivial wrapper around import.c's find_module()
(which, I believe, is what imp.find_module() invokes)

When multiple versions exist, the patch operates on what find_module() returns
(which ends up using the preference order '.py', '.pyw', '.py[co]')

Cheers,
Nick.

-- 
Nick Coghlan
Brisbane, Australia


More information about the Python-Dev mailing list