[Python] Diference between os.getcwd() and os.path.dirname(__file__)

Discussão em 'Python' iniciado por Stack, Agosto 18, 2025.

  1. Stack

    Stack Membro Participativo

    In a previous project, I used the first version of the following two lines. Now that I found getcwd() I thought this would be the shorter alternative.

    print(os.path.dirname(__file__)) # D:/Personal_Software/my_project
    print(os.getcwd()) # D:\Personal_Software\my_project


    I already read this post, but the thing I'm curious about is the use of "/" vs. "\". I'm using Windows 10 if that's relevant.

    Continue reading...

Compartilhe esta Página