检查数据库中是否存在该路径 [英] Check if the path exists in Databricks

查看:14
本文介绍了检查数据库中是否存在该路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Python检查该路径是否存在于数据库中:

try:
  dirs = dbutils.fs.ls ("/my/path")
  pass
except IOError:
  print("The path does not exist")

如果路径不存在,我希望except语句执行。 但是,不是except语句,而是try语句失败,错误为:

java.io.FileNotFoundException: GET ...
ErrorMessage=The specified path does not exist.

如何正确捕获FileNotFoundException

推荐答案

以下是备选

import os
dir = "/dbfs/path_to_directory"

if not os.path.exists(dir):
  print('The path does not exist')
  raise IOError

这篇关于检查数据库中是否存在该路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆