On Sat, Nov 14, 2020 at 7:56 AM Steven D'Aprano <steve@pearwood.info> wrote:
On Fri, Nov 13, 2020 at 05:59:29AM -0400, André Roberge wrote:

> 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.

What if you import the `__main__` module? What does `__imported__` say
now, and how do you check for "running as a script" if `__main__` has
imported itself -- or some other module has imported it?

Running a module (no matter what its name is) from a command line would set __imported__ to False for that module.
Using import some_module (or __import__("some_module")) would set some_module.__imported__ to True.

Is this `__imported__` variable *instead of* or *as well as* the
proposed `__main__`?

Sorry, I should have been clearer: __imported__ was made as an alternative suggestion to __main__: I completely agree that it would be silly to have both.

For beginners, I believe that it would be easier to understand what it means, which is the reason I had used something very similar in a project that has been shelved for the foreseeable future,




Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/ACTQZ3IIR4IPBTPLZAZ4SS5JR7R2HFNO/
Code of Conduct: http://python.org/psf/codeofconduct/