[Python-ideas] PEP for executing a module in a package containing relative imports
Adam Atlas
adam at atlas.st
Fri Apr 20 19:48:36 CEST 2007
On 19 Apr 2007, at 23.38, Brett Cannon wrote:
> Open Issues
> ===========
>
> A counter-proposal to introducing the ``__main__`` attribute on
> modules was to introduce a built-in with the same name. The value of
> the built-in would be the name of the module being executed (just like
> the proposed ``sys.main``). This would lead to a new idiom of::
>
> if __name__ == __main__:
> ...
I like that one. But one thing I've always thought would be handy is
a builtin (maybe __this__?) pointing to the current module object
itself (instead of its name). Any chance of that happening? In that
case, __main__ could globally point to the main module instead of its
name. The idiom would then be "if __this__ is __main__:...'. I think
that reads pretty well: "If this is [the] main [module, then ...]."
More information about the Python-ideas
mailing list