Python Forum

Full Version: modifying path in build files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Friends,

I ma having build files its having below paths
d:\foo\project\build\out
d:\foo\project\build\tools\py_automation_dev

my python script available in d:\foo\project\build\tools\py_automation_dev path actually i need d:\foo\project\build\out this path todo some task in in my python script.

note:my project path remains same every time, but d:\foo this path will change every time
Something like this maybe if I understand correctly
from pathlib import Path

path1 = Path(r'd:\foo\project\build\tools\py_automation_dev')
path2 = Path(r'd:\bah\project\build\tools\py_automation_dev')

def new_path(path):
    return Path(*path.parts[:2]).joinpath(Path(r'project\build)'))

print(new_path(path1))
print(new_path(path2))
Output:
d:\foo\project\build) d:\bah\project\build)