Revision 1 as of 2005-03-02 17:58:05

Clear message

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

__main__

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):
   2 
   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.