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
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
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 -- firstname.lastname@example.org
To unsubscribe send an email to email@example.com
Message archived at https://firstname.lastname@example.org/message/ACTQZ3IIR4IPBTPLZAZ4SS5JR7R2HFNO/
Code of Conduct: http://python.org/psf/codeofconduct/