[Python] How to use "/" (directory separator) in both Linux and Windows in Python?

Discussão em 'Python' iniciado por Stack, Dezembro 9, 2024.

  1. Stack

    Stack Membro Participativo

    I have written a code in python which uses / to make a particular file in a folder, if I want to use the code in windows it will not work, is there a way by which I can use the code in Windows and Linux.

    In python I am using this code:

    pathfile=os.path.dirname(templateFile)
    rootTree.write(''+pathfile+'/output/log.txt')


    When I will use my code in suppose windows machine my code will not work.

    How do I use "/" (directory separator) in both Linux and Windows?

    Continue reading...

Compartilhe esta Página