• Diplomjodler@lemmy.world
    link
    fedilink
    arrow-up
    24
    ·
    17 hours ago

    I always get irrationally angry when i see python code using os.path instead of pathlib. What is this, the nineties?

      • Diplomjodler@lemmy.world
        link
        fedilink
        arrow-up
        6
        ·
        10 hours ago
        • Everything is in one library which offers consistency for all operations.
        • You can use forward slashes on Windows paths, which makes for much better readability.
        • You can access all the parts of a pathlib object with attributes like .stem, .suffix or .parent.
        • You can easily find the differences between paths with .relative_to()
        • You can easily build up complex paths with the / operator (no string additions).

        Just off the top of my head.

        • brucethemoose@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          3 hours ago

          I suppose os.path is simpler? It’s a string and operation.

          Python is all about ‘attention efficiency,’ which there’s something to be said for. People taking the path of least resistance (instead of eating time learning the more complex/OOP pathlib) to bang out their script where they just need to move a file or something makes sense. I’m with you here, but it makes sense.


          …Also, os.path has much better Google SEO, heh.