Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How To Modify This Code??
#3
endswith() can take tuple as parameter.
Using os.scandir() is faster than listdir().
import os

with os.scandir('.') as it:
    count = 0
    for pic in it:
        if pic.name.endswith(('.jpg', '.png')):
            count += 1            
    print(count)
This will count all jpg  and png images in a folder.
If need a separate count,split it up like heiner55 show.
Reply


Messages In This Thread
How To Modify This Code?? - by digitalmatic7 - Nov-18-2017, 02:38 AM
RE: How To Modify This Code?? - by heiner55 - Nov-18-2017, 03:32 AM
RE: How To Modify This Code?? - by snippsat - Nov-18-2017, 08:06 AM
RE: How To Modify This Code?? - by digitalmatic7 - Nov-18-2017, 11:05 AM
RE: How To Modify This Code?? - by digitalmatic7 - Nov-18-2017, 04:25 PM
RE: How To Modify This Code?? - by snippsat - Nov-18-2017, 04:27 PM
RE: How To Modify This Code?? - by digitalmatic7 - Nov-18-2017, 04:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Modify code from running program ? samuelbachorik 2 2,487 Jun-26-2020, 08:17 PM
Last Post: samuelbachorik
  Modify code BlackPimpernel 3 3,409 Apr-02-2018, 03:48 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020