python获取当前脚本路径和父目录

def GetParentPath(strPath):
    if not strPath:
        return None;
    
    lsPath = os.path.split(strPath);
    print(lsPath);
    print("lsPath[1] = %s" %lsPath[1]);
    if lsPath[1]:
        return lsPath[0];
    
    lsPath = os.path.split(lsPath[0]);
    return lsPath[0];
        

strPath = GetCurrPath();
print("curr path: %s" %strPath);

#print(GetParentPath(strPath));

strPath += "/";
print(GetParentPath(strPath));

print(GetParentPath("/"));
 

你可能感兴趣的:(python,脚本,OS)