[Python-ideas] PEP for executing a module in a package containing relative imports

Aahz aahz at pythoncraft.com
Mon Apr 23 01:11:38 CEST 2007


On Sun, Apr 22, 2007, Steven Bethard wrote:
> On 4/22/07, Christian Heimes <lists at cheimes.de> wrote:
>>
>> I'm proposing the following changes:
>>
>> * sys.main is added which contains the dotted name of the main script.
>>    This allows code like:
>>
>>      if __name__ == sys.main:
>>          ...
> 
> Note that this really requires the code::
> 
>     import sys
>     if __name__ == sys.main:
> 
> The import statement matters to me because 77% of my modules that use
> the __main__ idiom *don't* import sys. Hence, for those modules, this
> new idiom introduces more boilerplate.

Does this follow the axiom that 83% of all statistics are made up on the
spot?  ;-)  Seriously, if I'm writing a script that requires __main__,
chances are excellent that it already includes sys (because it's
probably a command-line script that's graduating to module status).
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"...string iteration isn't about treating strings as sequences of strings, 
it's about treating strings as sequences of characters.  The fact that
characters are also strings is the reason we have problems, but characters 
are strings for other good reasons."  --Aahz



More information about the Python-ideas mailing list