Python Forum
modifying path in build files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
modifying path in build files
#1
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
Reply
#2
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)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020