Module name does not match file name

Steven D'Aprano steve at
Mon Jul 7 10:57:00 CEST 2014

Ah, I think I have a partial answer... but not a complete answer.

On Mon, 07 Jul 2014 07:57:21 +0000, Steven D'Aprano wrote:

> Can anyone explain how "import pg" can end up coming from
> Sure enough:
>>>> import pg
>>>> pg.__file__
> '/usr/local/lib/python2.6/dist-packages/'

I've looked inside the pgmodule.c source code, and it includes this 

extern void
    char *p;
    int i;

    Py_InitModule("pg", pg_methods);

which suggests that the file creates a module called "pg". 
What I don't understand is how "import pg" gets turned into "run"?


More information about the Python-list mailing list