What is the difference between pathlib glob(‘*’) and iterdir?

Suppose I'm writing code using pathlib and I want to iter over all the files in the same level of a directory.

I can do this in two ways:

p = pathlib.Path('/some/path')
for f in p.iterdir():
    print(f)
p = pathlib.Path('/some/path')
for f in p.glob('*'):
    print(f)

Is one of the options better in any way?



Read more here: https://stackoverflow.com/questions/63001429/what-is-the-difference-between-pathlib-glob-and-iterdir

Content Attribution

This content was originally published by kaki gadol at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: