#!/usr/bin/env python # -*- coding: utf-8 -*- # # "Hello Friends" in Chinese: 朋友你好 import os import sys import time from argparse import ArgumentParser def set_v_print(verbose): """ Defines the function v_print. It prints if verbose is true, otherwise, it does nothing. See: http://stackoverflow.com/questions/5980042 :param verbose: A bool to determine if v_print will print its args. """ global v_print if verbose: def v_print(*s): print ' '.join([i.encode('utf8') for i in s]) else: v_print = lambda *s: None def main(debug): start_time = time.time() localdir = os.path.abspath(os.path.dirname(sys.argv[0])) v_print("(verbose mode) debug =", str(debug)) v_print("(verbose mode) debug = %s, localdir = %s" % (repr(debug), localdir)) print "Done. That took %1.2fs." % (time.time() - start_time) if __name__ == '__main__': parser = ArgumentParser(description='Just a template sample.') parser.add_argument('-d', '--debug', action='store_true') parser.add_argument('-v', '--verbose', action='store_true') args = parser.parse_args() set_v_print(args.verbose) main(args.debug)