Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'importerror:': 0.07; 'subject:file': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'suffix': 0.09; 'python': 0.11; 'creates': 0.14; '"run': 0.16; 'ah,': 0.16; 'extern': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'alpha': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'module': 0.19; 'seems': 0.21; 'feb': 0.22; '>>>': 0.22; 'code,': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'char': 0.24; 'mon,': 0.24; "i've": 0.25; 'source': 0.25; 'gets': 0.27; 'header:X -Complaints-To:1': 0.27; 'tried': 0.27; '"",': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'void': 0.31; 'anyone': 0.31; 'file': 0.32; '(most': 0.33; 'but': 0.35; 'too': 0.37; 'to:addr:python-list': 0.38; 'short': 0.38; 'recent': 0.39; 'explain': 0.39; 'skip:. 10': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'how': 0.40; 'complete': 0.62; 'more': 0.64; 'answer.': 0.68; 'jul': 0.74; 'touch': 0.74; '2014,': 0.84; 'partial': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Module name does not match file name Date: Mon, 07 Jul 2014 12:41:15 +0200 Organization: None References: <53ba52e1$0$2926$c3e8da3$76491128@news.astraweb.com> <53ba60dc$0$2926$c3e8da3$76491128@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd89b4.dip0.t-ipconnect.de User-Agent: KNode/4.11.5 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1404729695 news.xs4all.nl 2856 [2001:888:2000:d::a6]:53165 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74092 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 "", line 1, in ImportError: ./alphamodule.so: file too short