What exactly are the advantages of os
compared to pathlib
? To me pathlib seems nearly always the better choice, especially because most of the functionality of os
can be reproduced by pathlib.os
if I am not mistaken. So is the only advantage of os
, that it is more lightweight?
Asked
Active
Viewed 234 times
0

LC117
- 426
- 4
- 12
-
1`os` existed in Python 2 already. `pathlib` entered in Python 3.4. – Matthias Apr 21 '21 at 11:43
-
You can start with [_Why an object-oriented API_](https://www.python.org/dev/peps/pep-0428/#why-an-object-oriented-api) section of PEP428 and also [this article](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) is good. It's interesting how you define `lightweight` (re `os` module). – buran Apr 21 '21 at 11:54
-
I only used `os` for working on paths until now, but it can do way more than that. I think what confused me, is that I thought that `pathlib.os` contained the entire `os`-module. So I assumed that `os` was just part of pathlib. – LC117 Apr 22 '21 at 06:54
-
As far as I know `pathlib.os` is not part of the official API. But looking at it, it seems to be a reference to the standard `os` module. Check it with `import pathlib; print(pathlib.os)`. – Matthias Apr 22 '21 at 08:00