Module name does not match file name

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Jul 7 07:56:31 EDT 2014


On Mon, 07 Jul 2014 12:15:51 +0100, Robert Kern wrote:

> On 2014-07-07 09:57, Steven D'Aprano wrote:
>> What I don't understand is how "import pg" gets turned into "run
>> pgmodule.so"?
> 
> This has been standard Python behavior for extension modules since
> forever. It's a very old practice and not recommended for new code,
> though.

Hmmm. Well, that is very special. Is this documented anywhere?

I know very little about extension modules. If I just rename the source 
file from pgmodule.c to pg.c, recompile to pg.so, and use that in place 
of pgmodule.so, is anything likely to break?



> |1> import imp
> 
> [~]
> |2> imp.get_suffixes()
> [('.so', 'rb', 3), ('module.so', 'rb', 3), ('.py', 'U', 1), ('.pyc',
> 'rb', 2)]


That seems to be gone in Python 3.3:


py> imp.get_suffixes()
[('.cpython-33m.so', 'rb', 3), ('.abi3.so', 'rb', 3), ('.so', 'rb', 3), 
('.py', 'U', 1), ('.pyc', 'rb', 2)]


-- 
Steven



More information about the Python-list mailing list