Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; 'subject:file': 0.07; '3),': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'creates': 0.14; '"run': 0.16; '1),': 0.16; '2)]': 0.16; 'ah,': 0.16; 'extern': 0.16; 'kern': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'underlying': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'module': 0.19; 'code,': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'char': 0.24; 'interpret': 0.24; 'mon,': 0.24; "i've": 0.25; 'source': 0.25; 'extension': 0.26; 'gets': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'robert': 0.30; "d'aprano": 0.31; 'steven': 0.31; 'though.': 0.31; 'void': 0.31; 'anyone': 0.31; 'file': 0.32; 'but': 0.35; 'to:addr:python-list': 0.38; 'explain': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'how': 0.40; 'new': 0.61; 'complete': 0.62; 'our': 0.64; 'world': 0.66; 'believe': 0.68; 'answer.': 0.68; 'jul': 0.74; 'behavior': 0.77; 'eco': 0.84; 'imp': 0.84; 'partial': 0.84; 'terrible': 0.84; 'forever.': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: Module name does not match file name Date: Mon, 07 Jul 2014 12:15:51 +0100 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=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 213.1.240.226 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <53ba60dc$0$2926$c3e8da3$76491128@news.astraweb.com> 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: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1404731768 news.xs4all.nl 2831 [2001:888:2000:d::a6]:58763 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74093 On 2014-07-07 09:57, 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"? This has been standard Python behavior for extension modules since forever. It's a very old practice and not recommended for new code, though. [~] |1> import imp [~] |2> imp.get_suffixes() [('.so', 'rb', 3), ('module.so', 'rb', 3), ('.py', 'U', 1), ('.pyc', 'rb', 2)] -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco