Re: __main__ vs official module name: distinct module instances

2015-08-04 Thread Jonas Wielicki
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 On 02.08.2015 05:53, Cameron Simpson wrote: > When invoked this way, the module cs.app.maildb that is being > executed is actually the module named "__main__". If some other > piece of code imports "cs.app.maildb" they get a _different_ > instance

Re: __main__ vs official module name: distinct module instances

2015-08-02 Thread Cameron Simpson
On 02Aug2015 18:18, Chris Angelico wrote: On Sun, Aug 2, 2015 at 6:16 PM, Chris Angelico wrote: On Sun, Aug 2, 2015 at 5:41 PM, Steven D'Aprano 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 afte

Re: __main__ vs official module name: distinct module instances

2015-08-02 Thread Cameron Simpson
On 02Aug2015 17:41, Steven D'Aprano wrote: On Sun, 2 Aug 2015 01:53 pm, Cameron Simpson wrote: Maybe this should be over in python-ideas, since there is a proposal down the bottom of this message. But first the background... I've just wasted a silly amount of time debugging an issue that reall

Re: __main__ vs official module name: distinct module instances

2015-08-02 Thread Chris Angelico
On Sun, Aug 2, 2015 at 6:16 PM, Chris Angelico wrote: > On Sun, Aug 2, 2015 at 5:41 PM, Steven D'Aprano 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: >> >>

Re: __main__ vs official module name: distinct module instances

2015-08-02 Thread Chris Angelico
On Sun, Aug 2, 2015 at 5:41 PM, Steven D'Aprano 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 >

Re: __main__ vs official module name: distinct module instances

2015-08-02 Thread Steven D'Aprano
On Sun, 2 Aug 2015 01:53 pm, Cameron Simpson wrote: > Hi All, > > Maybe this should be over in python-ideas, since there is a proposal down > the bottom of this message. But first the background... > > I've just wasted a silly amount of time debugging an issue that really I > know about, but had

Re: __main__ vs official module name: distinct module instances

2015-08-01 Thread Chris Angelico
On Sun, Aug 2, 2015 at 1:53 PM, Cameron Simpson wrote: > What are the implications of modifying the python invocation: > > python -m cs.app.maildb > > to effectively do this (Python pseudo code): > > M = importlib.import("cs.app.maildb") > M.__name__ = '__main__' > sys.modules['__main__'] = M