def append_slash_if_dir(p): if p and os.path.isdir(p) and p[-1] != os.sep: return p + os.sep else: return p