[Python-ideas] Replacing the if __name__ == "__main__" idiom (was Re: making a module callable)
Alexander Belopolsky
alexander.belopolsky at gmail.com
Tue Nov 26 04:04:59 CET 2013
On Mon, Nov 25, 2013 at 9:37 PM, Ron Adam <ron3200 at gmail.com> wrote:
> It could be used within functions. Currently __name__ is masked by the
> function's __name__ attribute if you try that.
>
That's news to me. It was not so as of 3.3.3:
Python 3.3.3 (default, Nov 25 2013, 15:41:46)
>>> def f():
... print(__name__)
...
>>> f()
__main__
If anything, it is a magic function relying on _getframe() run-time
introspection that would have a problem working inside functions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131125/c6101ee2/attachment.html>
More information about the Python-ideas
mailing list