hulk007 hulk007 - 1 year ago 65
Python Question

how to use "/" (directory separator) in both Linux and Windows?

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 command:


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

Please help me here!

Answer Source

Use os.path.join(). Example: os.path.join(pathfile,"output","log.txt").

In your code that would be: rootTree.write(os.path.join(pathfile,"output","log.txt"))

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download