On 25/11/2013 22:25, אלעזר wrote:
2013/11/24 Guido van Rossum <guido@python.org <mailto:guido@python.org>>
if is_main(): <do your main code>
How about going the other way around?
if imported(): break
<do your main code>
Most of the time, people put the main stuff at the end of the script, so this check can serve as a seperator, equivalent to what is sometimes marked with '***********************' - snip the script here.
Of course, it is still possible to do
if not imported(): main()
I think it is at least as obvious as is_main(), and even more so for those without a C-like background.
(Personally I'd prefer an `imported` magic variable but I guess that's out of question).
Instead of "imported", how about "import"? That already exists as a reserved word and its use outside an import statement is currently illegal: if not import: main()