i wish to improve the following function. Given a Pixel data types in GDAL (ex: "Int16") resturn a code number.
def GDAL_data_type(dataType):
dtypes = {
"Unknown": 0,
"Byte": 1,
"UInt16": 2,
"Int16": 3,
"UInt32": 4,
"Int32": 5,
"Float32": 6,
"Float64": 7,
"CInt16": 8,
"CInt32": 9,
"CFloat32": 10,
"CFloat64": 11
}
return dtypes[dataType]
GDAL_data_type("Int16")
3
I wish to insert a error message in the function where if you type a dataType different, the error message say:
raise SystemExit('Pixel data type no recognized %s' % dataType)
I wish to ask the best way to insert this error message in my function. Thanks in advance
Wrap the dictionary lookup in a try block, catch the keyerror exception, and raise your own from the catch block:
EDIT
Or more fully: