import sys, os, errno def atoi(v): try: return int(v or 0) except ValueError: return 0 def unlink(f): """Delete a file at path 'f' if it currently exists. Unlike os.unlink(), does not throw an exception if the file didn't already exist. """ try: os.unlink(f) except OSError, e: if e.errno == errno.ENOENT: pass # it doesn't exist, that's what you asked for def mkdirp(d, mode=None): """Recursively create directories on path 'd'. Unlike os.makedirs(), it doesn't raise an exception if the last element of the path already exists. """ try: if mode: os.makedirs(d, mode) else: os.makedirs(d) except OSError, e: if e.errno == errno.EEXIST: pass else: raise