First, see if there is splitunc() as an available function in os.path . The first returned item should be what you want ... but I'm on Linux and I don't have this function when I import os and try to use it.
Otherwise, one semi-fun way to do this work is to use:
>>> pathname = "\\C:\\mystuff\\project\\file.py" >>> pathname '\\C:\\mystuff\\project\\file.py' >>> print pathname \C:\mystuff\project\file.py >>> "\\".join(pathname.split('\\')[:-2]) '\\C:\\mystuff' >>> "\\".join(pathname.split('\\')[:-1]) '\\C:\\mystuff\\project'
which shows extracting the directory directly above the file and the directory just above it.
ely Apr 13 '12 at 23:00 2012-04-13 23:00
source share