[Python-ideas] Re: Global flag for whether a module is __main__

2020-11-13 Thread André Roberge
On Thu, Nov 12, 2020 at 9:46 AM Matt Wozniski wrote: > Currently, the simplest and most idiomatic way to check whether a module > was > run as a script rather than imported is: > > if __name__ == "__main__": > > People generally learn this by rote memorization, because users often want > the

[Python-ideas] Re: Global flag for whether a module is __main__

2020-11-13 Thread Henshaw, Andy via Python-ideas
Excellent redirect of original proposal: +10 From: André Roberge [snip] As a goal of making it even more obvious what the (new) idiom mans, I would suggest a variable named __imported__ with the opposite value to what is proposed. Thus, if not __imported__: would behave the same as the prop

[Python-ideas] Re: Global flag for whether a module is __main__

2020-11-13 Thread Steven D'Aprano
On Thu, Nov 12, 2020 at 06:33:52PM +, Rob Cliffe via Python-ideas wrote: > I find this a curious argument.  A bit like saying "Here are your new > shoes; they weigh 10Kg but that's absolutely great because you'll > develop stronger legs wearing them". Do you honestly think that writing

[Python-ideas] Re: Global flag for whether a module is __main__

2020-11-13 Thread Steve Barnes
I love the idea of __imported__ but would like to suggest taking it even further - why not, rather that a bool for __imported__, have the value of it be either None (if __name__ == "__main__") or the __name__ of the module that it is being imported from. This could potentially be useful in tryin