0
我有一個數據庫目錄讀取圖像路徑以及其他屬性,並有一個部分,試圖打開代碼中的數據集,以便其他進程可以繼續,如果開放是成功的但我碰到了一個絆腳石,關於如何告訴程序在下面的代碼後繼續執行,代碼運行順利,但是當它遇到圖像時,它不能打開它停止,而不是開始再次讀取數據庫並打開一個新的形象。python和gdal圖像處理
try:
hDataset = gdal.Open(pszFilename, gdal.GA_ReadOnly)
except IOError:
print("gdalinfo failed - unable to open '%s'." % pszFilename)
status = "UPDATE %s SET job = 11 WHERE id = %s" % (table,row[2])
setstatus = conn.cursor()
setstatus.execute(status)
conn.commit()
setstatus.close()
else:
print "file opened sucessfully"
hDataset.close()
嘗試確定哪一行引起的掛起(少數診斷打印語句可能會告訴你)。請注意,並非所有'gdal.Open'失敗都會生成一個'IOError'異常(例如,如果該文件不存在,則不會拋出異常),因此您可能還需要捕獲一般異常。 – bogatron