A system independent way using python to get the root directory/drive on which python is installed

Bentley4 picture Bentley4 · Aug 20, 2012 · Viewed 45.3k times · Source

For Linux this would give me /, for Windows on the C drive that would give me C:\\. Note that python is not necessarily installed on the C drive on windows.

Answer

user2743490 picture user2743490 · Mar 7, 2014

Try this:

import os

def root_path():
    return os.path.abspath(os.sep)

On Linux this returns /

On Windows this returns C:\\ or whatever the current drive is