Your search query "linkto%3A%22Decorators%22" didn't return any results. Please change some terms and refer to HelpOnSearching for more information.
(!) Consider performing a full-text search with your search terms.

Clear message

A page for useful (or potentially abusive?) decorator ideas.


This decorator does not alter a function, but causes it to be executed if __name__ == '__main__'. This provides an experimental cleaner syntax to the traditional way of bootstrapping a python script. This should not be used on class methods.

The function gets a copied list of sys.argv arguments.

   1 def __main__(func):
   3     if __name__ == "__main__":
   4         import sys, os
   5         args = sys.argv[:]
   6         args[0] = os.path.abspath(args[0])
   7         func(args)

Unable to edit the page? See the FrontPage for instructions.