Skip to content

Pythonmodulestandalonemain

johnnyquest edited this page Jun 9, 2011 · 1 revision

(python) module/standalone main

With this snippet at the end of a .py file, it can also be used as a standalone app besides of importing it as a module.

if __name__=="__main__":

    if len(sys.argv)>1:
        try:
            main(sys.argv[1:])
        except:
            print "OOPS: main() failed"
            print traceback.format_exc()
    else:
        print "usage: %s [arguments]" % sys.argv[0]
Clone this wiki locally