Pathlib suggestion

For some of these operations, pathlib is probably the way to go by this point. Here's an example alternative for the following snippet:


>>> from pathlib import Path
>>> [x.name for x in Path('.').iterdir()]
['avocado.jpg', 'kiwifruit.jpg', 'lemon.jpg', 'apple.jpg', 'strawberry.jpg', 'rename-images.py', 'orange.jpg']


Pathlib can be used for globs as well, so has a lot of flexibility.


Link to content: Useful Python - Section 2

2 Likes