I want to display images continuously using the for statement.

Asked 2 years ago, Updated 2 years ago, 345 views

import glob
from PIL import Image

    Enter code here
    image_paths=glob.glob('test_data/test/'+"*.jpg")
    image_paths = [ image_paths ]

    for in image_paths:
        img=Image.open(i)
AttributeError Traceback (most recent call last)
File/opt/anaconda3/lib/python3.9/site-packages/PIL/Image.py:2957, in open (fp, mode, formats)
   2956try:
->2957fp.seek(0)
   2958 except (AttributeError,io.UnsupportedOperation):

AttributeError: 'list' object has no attribute' seek'

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)
Input In[28], in<cellline:1>()
      1 for in image_paths:
---->2img=Image.open(i)

File/opt/anaconda3/lib/python3.9/site-packages/PIL/Image.py:2959, in open (fp, mode, formats)
   2957fp.seek(0)
   2958 except (AttributeError,io.UnsupportedOperation):
->2959fp=io.BytesIO(fp.read())
   2960 exclusive_fp = True
   2962 prefix = fp.read(16)

AttributeError: 'list' object has no attribute 'read'

python

2022-09-30 22:04

1 Answers

Removing the image_paths=[image_paths] line will continue to change the behavior.

image_paths=glob.glob('test_data/test/'+"*.jpg') results in a list, so image_paths=[image_paths] may result in a list of image_paths contents.

The source code provided does not mention the action to be displayed, so it may just end over time.


2022-09-30 22:04

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.