How about some syntactic sugar for " __name__ == '__main__' "?
Skip Montanaro
skip.montanaro at gmail.com
Wed Nov 12 16:55:04 EST 2014
More information about the Python-list mailing list
Wed Nov 12 16:55:04 EST 2014
- Previous message (by thread): How about some syntactic sugar for " __name__ == '__main__' "?
- Next message (by thread): How about some syntactic sugar for " __name__ == '__main__' "?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> 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
- Previous message (by thread): How about some syntactic sugar for " __name__ == '__main__' "?
- Next message (by thread): How about some syntactic sugar for " __name__ == '__main__' "?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list