Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中打开的文件太多_Python_Django_Python Imaging Library - Fatal编程技术网

python中打开的文件太多

python中打开的文件太多,python,django,python-imaging-library,Python,Django,Python Imaging Library,我正在尝试调整图像的大小。它工作正常,但my(即至_字段)正在打开但未关闭。因此,我有一个错误打开的文件太多。我尝试了一些解决方案,但没能解决问题。代码如下: if( to_field.width != size[0] and to_field.height != size[1] ): to_field.open() image = Image.open(StringIO(to_field.read())) old_file_path = to_field.path im

我正在尝试调整图像的大小。它工作正常,但my(即
至_字段
)正在打开但未关闭。因此,我有一个错误
打开的文件太多
。我尝试了一些解决方案,但没能解决问题。代码如下:

if( to_field.width != size[0] and to_field.height != size[1] ):
   to_field.open()
   image = Image.open(StringIO(to_field.read()))
   old_file_path = to_field.path
   image.resize(size).save(to_field.path)

有什么建议吗?

老问题,但我认为django字段到_字段需要关闭:

to_field.close()

您是否/应该
image.close()
?(不熟悉PIL…)是的,我试过了。没有属性“close”可能与的重复