Python 检查Databricks中是否存在该路径
我尝试使用Python检查Databricks中是否存在路径:Python 检查Databricks中是否存在该路径,python,databricks,azure-databricks,dbutils,Python,Databricks,Azure Databricks,Dbutils,我尝试使用Python检查Databricks中是否存在路径: try: dirs = dbutils.fs.ls ("/my/path") pass except IOError: print("The path does not exist") 如果路径不存在,我希望执行except语句。 但是,try语句不是except语句,而是失败,出现错误: java.io.FileNotFoundException: GET ... ErrorMessage=The specified
try:
dirs = dbutils.fs.ls ("/my/path")
pass
except IOError:
print("The path does not exist")
如果路径不存在,我希望执行except
语句。
但是,try
语句不是except
语句,而是失败,出现错误:
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