获取项目路径
def reversePath(abspath, iter):
if isinstance(iter ,str):
iter = int(iter)
if iter is None or iter == 0:
return abspath
else:
path = abspath
# 路径的深度
times = path.count('\\') or path.count('/')
if iter >= times:
# 翻转到路径最大深度,返回盘符
return path[0:path.find('\\') or path.find('/') ]
else:
for i in range(0, iter):
path = os.path.dirname(path)
return path
test
if __name__ == '__main__':
print(reversePath("D:\Document\py\workspace\robotFrame\workspace\vhl\VHLTngDog\TestNG_Demo\FunLibTestNG", 2))
print(reversePath("D:\Document\py\workspace\robotFrame\workspace\vhl\VHLTngDog\TestNG_Demo\FunLibTestNG", 12))
打印:
D:\Document\py\workspace\robotFrame\workspace\vhl\VHLTngDog
D:
浙公网安备 33010602011771号