所以我想出的解决方案是通过将给定文件跟随到根目录来构建文件系统的根目录:
def getRoot(file=None): if file is None: file='.' me=os.path.abspath(file) drive,path=os.path.splitdrive(me) while 1: path,folder=os.path.split(path) if not folder: break return drive+path os.path.join(getRoot(), 'etc', 'init.d')



