Differences between revisions 1 and 2
Revision 1 as of 2005-03-02 17:58:05
Size: 578
Editor: 160
Comment:
Revision 2 as of 2008-11-15 14:00:19
Size: 578
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

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.

Toggle line numbers
   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)

Decorators (last edited 2023-11-28 03:47:40 by RaviGupta)

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