# -*- coding: utf-8 -*- import getopt, sys def usage(): print "USAGE:", sys.argv[0], "[-h|d]" try: opts, args = getopt.getopt(sys.argv[1:], "hd", ["help", "debug"]) except getopt.GetoptError: # print help information and exit: usage() sys.exit(2) debug_mode = False for o, a in opts: if o in ("-d", "--debug"): debug_mode = True if o in ("-h", "--help"): usage() sys.exit() def debug(txt): if debug_mode: print txt.encode('utf8')