[英]Python: Close a file opened with scipy.misc.imread
在Python中,可以像下面這樣用scipy讀取圖像:
from scipy.misc import imread
img = imread('cats.jpg')
如何關閉打開的文件?
好的,Scipy在后台使用PIL,並且PIL支持with
塊語法,該語法在退出塊時自動關閉文件:
from PIL import Image
with Image.open('test.png') as test_image:
do_things(test_image)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.