0

I have two paths to a file like below;

old_path_1 = 'old_path_1/12374994/12324515/000000.dcm'

old_path_2 = 'old_path_2/07-20-2016-DDSM-74994/1_full_24515/000000.dcm'

I want to have a new path like below in order to create .csv file, that contains the correct paths to all images.

new_path = 'old_path_1/07-20-2016-DDSM-74994/1_full_24515/000000.dcm' 

** only 12374994/12324515 must be replaced by 07-20-2016-DDSM-74994/1_full_24515.

I have to do this as there are some inconsistent in the path of the original file. Could anyone show me how can we do this in python in simpler way?

this is what I did;

old_path_1.split('/')[0]+ '/' + old_path_2.split('/')[1]+'/' +old_path_2.split('/')[2]+'/' +old_path_1.split('/')[3]

is there any better way?

Mass17
  • 1,555
  • 2
  • 14
  • 29
  • Is the part to replace always in the same area? Take a look at https://stackoverflow.com/questions/3167154/how-to-split-a-dos-path-into-its-components-in-python. – AMC Mar 04 '20 at 17:52

1 Answers1

0

I think your question needs some more explanation about the general case you're dealing with. However, if this is the only case you're dealing then you only need to replace the '2' in old_path_2 in a '1' so:

new_path = old_path_2
new_path[9] = '1'

Or, if you're looking for a one liner:

new_path = old_path_1[:10] + old_path_2[10:]
DvirH
  • 70
  • 8