Check if the path exists in Databricks(检查数据库中是否存在该路径)
问题描述
我尝试使用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
这篇关于检查数据库中是否存在该路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!