I am trying to merge 2 overlapping paths in the following way:
wd= /home/user/project1/scripts/test1
path=~/project1/task1/file.txt
output= /home/user/project1/task1/file.txt
I have tried what suggested in similar posts but I don't get my desired output:
wd='/home/user/project1/scripts/test1'
path='~/project1/task1/file.txt'
print(os.path.join(wd, path))
CodePudding user response:
I would suggest using this solution:
import os
wd = '/home/user/project1/scripts/test1'
path = '~/project1/task1/file.txt'
output = wd '/' os.path.basename(path)
print(output)
CodePudding user response:
How about trying this?
import os
wd= '/home/user/project1/scripts/test1'
path='~/project1/task1/file.txt'
path = path.replace('~','/home/user')
print(path)
It outputs "/home/user/project1/task1/file.txt"
