Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74092

Re: Module name does not match file name

From Peter Otten <__peter__@web.de>
Subject Re: Module name does not match file name
Date 2014-07-07 12:41 +0200
Organization None
References <53ba52e1$0$2926$c3e8da3$76491128@news.astraweb.com> <53ba60dc$0$2926$c3e8da3$76491128@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.11582.1404729695.18130.python-list@python.org> (permalink)

Show all headers | View raw


Steven D'Aprano wrote:

> 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 pgmodule.so?
>> 
>> 
>> Sure enough:
>> 
>>>>> import pg
>>>>> pg.__file__
>> '/usr/local/lib/python2.6/dist-packages/pgmodule.so'
> 
> 
> 
> I've looked inside the pgmodule.c source code, and it includes this
> snippet:
> 
> 
> extern void
> initpg(void)
> {
>     char *p;
>     int i;
> 
>     Py_InitModule("pg", pg_methods);
> 
> 
> which suggests that the pgmodule.so file creates a module called "pg".
> What I don't understand is how "import pg" gets turned into "run
> pgmodule.so"?

It seems the suffix "module.so" is tried automagically by the import 
machinery:

$ touch alphamodule.so
$ python
Python 2.7.5+ (default, Feb 27 2014, 19:37:08) 
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import alpha
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: ./alphamodule.so: file too short

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Module name does not match file name Steven D'Aprano <steve@pearwood.info> - 2014-07-07 07:57 +0000
  Re: Module name does not match file name Chris Angelico <rosuav@gmail.com> - 2014-07-07 18:04 +1000
    Re: Module name does not match file name Steven D'Aprano <steve@pearwood.info> - 2014-07-07 09:03 +0000
      Re: Module name does not match file name Chris Angelico <rosuav@gmail.com> - 2014-07-07 19:11 +1000
  Re: Module name does not match file name Steven D'Aprano <steve@pearwood.info> - 2014-07-07 08:57 +0000
    Re: Module name does not match file name Chris Angelico <rosuav@gmail.com> - 2014-07-07 19:03 +1000
      Re: Module name does not match file name Steven D'Aprano <steve@pearwood.info> - 2014-07-07 09:28 +0000
    Re: Module name does not match file name Peter Otten <__peter__@web.de> - 2014-07-07 12:41 +0200
    Re: Module name does not match file name Robert Kern <robert.kern@gmail.com> - 2014-07-07 12:15 +0100
      Re: Module name does not match file name Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-07 11:56 +0000
        Re: Module name does not match file name Chris Angelico <rosuav@gmail.com> - 2014-07-07 22:04 +1000
        Re: Module name does not match file name Robert Kern <robert.kern@gmail.com> - 2014-07-07 15:25 +0100

csiph-web