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


Groups > comp.lang.python > #94893

Re: __main__ vs official module name: distinct module instances

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.021
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'cc:addr:python-list': 0.09; 'it;': 0.09; 'subject:module': 0.09; 'whichever': 0.09; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'module?': 0.16; 'runtimeerror': 0.16; 'send.': 0.16; 'sys.modules': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'instance,': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'import': 0.24; 'header :In-Reply-To:1': 0.24; 'chris': 0.26; 'message- id:@mail.gmail.com': 0.27; 'found.': 0.27; 'actual': 0.28; 'for,': 0.29; 'raise': 0.29; 'problem': 0.33; "d'aprano": 0.33; 'raising': 0.33; 'steven': 0.33; 'file': 0.34; 'that,': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'should': 0.36; 'possible': 0.36; 'modules': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'things': 0.38; 'mean': 0.38; 'sure': 0.39; 'does': 0.39; 'where': 0.40; 'some': 0.40; 'above,': 0.63; 'wish': 0.71; 'chrisa': 0.84; 'detecting': 0.84; 'premature': 0.84; 'subject:official': 0.84; 'to:none': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=cm+GtZaaUOCiVC+KPSKeUcnVL3GKTswNbrLn/jntmYA=; b=BlyBlH4RZ9X7EWbeC2I5uXQnXNrQ1UM9O1Je1XG4X2TrUWA0IaIGI6t/TgyBefMgYV ZhwOhX5RNJNiDn7Z8T/BCuEMA1+dyI06evHNXoJexw8lo/PwyYYx2AWRV8T0xS1BGFSU +wqFGTRsAYoe5i8KTtvt3zTAjbYWF0XBHKujD+vT2KU0iw50L5r440X4O1ovL4x+uwJH Ij6uc5xLM8m0YzCpvYFKye5qAdneimUF/rY4yWJYMkNZDc5XnbWCOO0b3PXKUUapvLV8 nzbOjkPgHv6lJHVHihmzgcqMjA+zERsqevdy818BAzbBfYkgEwdV2vtxqBqO5khw9A3n vWxw==
MIME-Version 1.0
X-Received by 10.107.163.16 with SMTP id m16mr14926048ioe.31.1438503516475; Sun, 02 Aug 2015 01:18:36 -0700 (PDT)
In-Reply-To <CAPTjJmoLRDarzHGAoLW6bUFXZHjgGpjpjdZp=8S2hoTDSQBK9A@mail.gmail.com>
References <mailman.1151.1438488073.3674.python-list@python.org> <55bdc996$0$1663$c3e8da3$5496439d@news.astraweb.com> <CAPTjJmoLRDarzHGAoLW6bUFXZHjgGpjpjdZp=8S2hoTDSQBK9A@mail.gmail.com>
Date Sun, 2 Aug 2015 18:18:36 +1000
Subject Re: __main__ vs official module name: distinct module instances
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1154.1438503524.3674.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1438503524 news.xs4all.nl 2937 [2001:888:2000:d::a6]:53287
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:94893

Show key headers only | View raw


On Sun, Aug 2, 2015 at 6:16 PM, Chris Angelico <rosuav@gmail.com> wrote:
> On Sun, Aug 2, 2015 at 5:41 PM, Steven D'Aprano <steve@pearwood.info> wrote:
>> * if you don't wish to do that, you're screwed, and I think that the
>>   best you can do is program defensively by detecting the problem
>>   after the event and bailing out:
>>
>>   # untested
>>   import __main__
>>   import myactualfilename
>>   if os.path.samefile(__main__.__path__, myactualfilename.__path__):
>>       raise RuntimeError
>
> Not sure what __path__ is here, as most of the things in my
> sys.modules don't have it; do you mean __file__? In theory, it should
> be possible to skim across sys.modules, looking for a match against
> __main__, and raising RuntimeError if any is found.

Oops, premature send.

*In theory* it should be possible to do the above, but whichever
attribute you look for, some modules may not have it. How does this
play with, for instance, zipimport, where there's no actual file name
for the module?

ChrisA

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


Thread

__main__ vs official module name: distinct module instances Cameron Simpson <cs@zip.com.au> - 2015-08-02 13:53 +1000
  Re: __main__ vs official module name: distinct module instances Steven D'Aprano <steve@pearwood.info> - 2015-08-02 17:41 +1000
    Re: __main__ vs official module name: distinct module instances Chris Angelico <rosuav@gmail.com> - 2015-08-02 18:16 +1000
    Re: __main__ vs official module name: distinct module instances Chris Angelico <rosuav@gmail.com> - 2015-08-02 18:18 +1000
    Re: __main__ vs official module name: distinct module instances Cameron Simpson <cs@zip.com.au> - 2015-08-03 10:57 +1000

csiph-web