Nope, not possible, really.
When __name__
is not '__main__'
your module was imported by another piece of code, as a regular module. You cannot bail out early in that case.
And what's wrong with a one time extra indentation level? Just hit tab in the editor, and be done with it? Personally, I find that using a main()
function documents the intent much better than leaving the code unindented.