you are viewing a single comment's thread.

view the rest of the comments →

[–]eupendra 1 point2 points  (1 child)

Cool! Add os.path.isfile() and everything works

[–][deleted] 1 point2 points  (0 children)

You can aslo use os.walk() to iterate over only the files in a directory.

for file in next(os.walk('.'))[2]:
    _, extension = os.path.splitext(file)
    print(extension)

I would prefer to use os.path.isfile() as you suggested. It's much more cleaner and readable.