OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

"Image.open(file).to_thumb(256,256)" is not working with variable containing file name , but it is working if I am giving the file name directly

  • Thread starter Thread starter Arushi_22
  • Start date Start date
A

Arushi_22

Guest
Code:
target_file = '/kaggle/working'/path/'forest'
i = 0
    for file in target_file.iterdir():
    print(file)
    Image.open(file).to_thumb(256,256)
    i+=1
    if i > 5:
        break

Output is as follows:

Code:
/kaggle/working/bird_or_not/forest/9c34f24c-5db1-4a03-9ef7-60b53f6e2b2e.jpg
/kaggle/working/bird_or_not/forest/e0062310-e425-4058-8bba-00a26b9b81bc.jpg
/kaggle/working/bird_or_not/forest/4ceb232b-8be0-4ede-ba38-85193e1fec91.jpg
/kaggle/working/bird_or_not/forest/d764afd2-8419-4de3-9372-498bb70cec65.jpeg
/kaggle/working/bird_or_not/forest/9a1e05f9-d31d-4c15-b819-e91290dd1c32.jpg
/kaggle/working/bird_or_not/forest/67ca71d8-6059-444f-8351-ec78eb19ae2b.jpeg

And If I give the specific file name, than it is working, i.e. After running the below command, I see the image

Image.open('bird_or_not/forest/ca274e96-48c9-46b3-9eeb-a98ddf3f665d.jpeg').to_thumb(256,256)

I want to why is it not working, if I am providing the file name in a variable format.
<pre><code>target_file = '/kaggle/working'/path/'forest'
i = 0
for file in target_file.iterdir():
print(file)
Image.open(file).to_thumb(256,256)
i+=1
if i > 5:
break
</code></pre>
<p>Output is as follows:</p>
<pre><code>/kaggle/working/bird_or_not/forest/9c34f24c-5db1-4a03-9ef7-60b53f6e2b2e.jpg
/kaggle/working/bird_or_not/forest/e0062310-e425-4058-8bba-00a26b9b81bc.jpg
/kaggle/working/bird_or_not/forest/4ceb232b-8be0-4ede-ba38-85193e1fec91.jpg
/kaggle/working/bird_or_not/forest/d764afd2-8419-4de3-9372-498bb70cec65.jpeg
/kaggle/working/bird_or_not/forest/9a1e05f9-d31d-4c15-b819-e91290dd1c32.jpg
/kaggle/working/bird_or_not/forest/67ca71d8-6059-444f-8351-ec78eb19ae2b.jpeg

</code></pre>
<p>And If I give the specific file name, than it is working, i.e. After running the below command, I see the image</p>
<p><code>Image.open('bird_or_not/forest/ca274e96-48c9-46b3-9eeb-a98ddf3f665d.jpeg').to_thumb(256,256)</code></p>
<p>I want to why is it not working, if I am providing the file name in a variable format.</p>
 

Latest posts

H
Replies
0
Views
1
hohohohoho
H
Top