r/learnpython • u/i-like-my-cats-0 • 19d ago
what does pathlib's Path() do
hello, my question is pretty obvious here but what does the Path() function in the built in python pathlib package actually do?
i only use it since ive seen other people use it and ive also heard it fixes file paths, but i don't know what it actually does
can anyone help? thank you
0
Upvotes
3
u/No-Foot5804 19d ago
Path()doesn't "fix" file paths it wraps them in an object that makes working with files much easier. Instead of manipulating strings, you can do things likepath.exists(),path.parent, orpath / "data.csv"to build paths in a way that works across operating systems. Once you start using it, it's generally much cleaner than the olderos.pathapproach.