> def main(func): > if func.__module__ == "__main__": > func() > return func # The return could be omitted to block the function from > being manually called after import. > > Just decorate the "main" function of the script with that, and it will be > automatically called when ran as a script, but not when imported as a > module.
This won't work (I don't think) if you want to call the "main" function from another place (like the interpreter prompt). Skip -- https://mail.python.org/mailman/listinfo/python-list