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


Groups > comp.lang.python > #94891

Re: __main__ vs official module name: distinct module instances

References <mailman.1151.1438488073.3674.python-list@python.org> <55bdc996$0$1663$c3e8da3$5496439d@news.astraweb.com>
Date 2015-08-02 18:16 +1000
Subject Re: __main__ vs official module name: distinct module instances
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1153.1438503398.3674.python-list@python.org> (permalink)

Show all headers | View raw


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.

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