[Python] How do I get the parent directory in Python?

Discussão em 'Python' iniciado por Stack, Maio 20, 2025.

  1. Stack

    Stack Membro Participativo

    Could someone tell me how to get the parent directory of a path in Python in a cross platform way. E.g.

    C:\Program Files ---> C:\


    and

    C:\ ---> C:\


    If the directory doesn't have a parent directory, it returns the directory itself. The question might seem simple but I couldn't dig it up through Google.

    Continue reading...

Compartilhe esta Página