如何检查图像数据是否可以从字典中返回



我目前正在编写一个Python模块,在函数的一部分中,我将tiff图像保存到字典中。然而,我不确定如何实际验证这一点?如何从保存tiff文件的字典中调用或返回数组?我只需要用返回optional_dict来结束我的函数吗?

optional_dict={}
if showMaps==True:#Conditional argument for saving the tiff image
#Tiff image saved in a temporary directory
with open(outputdir+f"ROI-{NAME}-thickness_tif", 'rb') as f:
thickness_tif = f.read()# Read tiff image
thickness_tif = optional_dict["thickness_tif"] #Save to dictionary with keyword

如果要将thickness_tif保存到字典optional_dict,则必须反转表达式:

# Save to dictionary with keyword
# INCORRECT: thickness_tif = optional_dict["thickness_tif"]
optional_dict["thickness_tif"] = thickness_tif

如果你想检查写了什么,你可以简单地print存储在字典中的值:

print(optional_dict["thickness_tif"])

最新更新