def safe_rmpath(path):
 try:
  st = os.stat(path)
  if stat.S_ISDIR(st.st_mode):
   os.rmdir(path)
  else:
   os.remove(path)
 except OSError as err:
  if (err.errno != errno.ENOENT):
   raise

def safe_rmpath ( path ) : try : st = os . stat ( path ) if stat . S_ISDIR ( st . st_mode ) : os . rmdir ( path ) else : os . remove ( path ) except OSError as err : if ( err . errno != errno . ENOENT ) : raise
convenience function for removing temporary test files or dirs .