[Python] pathlib vs. os.path.join in Python

Discussão em 'Python' iniciado por Stack, Março 27, 2025.

  1. Stack

    Stack Membro Participativo

    When I need to define a file system path in my script, I use os.path.join to guarantee that the path will be consistent on different file systems:

    from os import path
    path_1 = path.join("home", "test", "test.txt")


    I also know that there is the pathlib module that basically does the same:

    from pathlib import Path
    path_2 = Path("home") / "test" / "test.txt"


    What is the difference between these two ways to handle paths? Which one is better?

    Continue reading...

Compartilhe esta Página