2

I currently have the below Python code which works well:-

caseURL = r"\\mydomain\abc\lp_t\GB\123456\Original Format"
caseURL = caseURL.replace("lp_t", "lp_i")
caseURL = caseURL.replace("Original Format", "1")

This works fine as said and carries out the below conversion:-

\\mydomain\abc\lp_t\GB\123456\Original Format 
\\mydomain\abc\lp_i\GB\123456\1\

This however just seems a bit clumsy. Is there a more pythonesque way to perform these two segment replacements?

Thanks

thefragileomen
  • 1,537
  • 8
  • 24
  • 40
  • 1
    The other way I can think of is regex. Would you like a solution in that – Rahul Agarwal Dec 04 '18 at 12:18
  • 1
    The only thing you might want to consider is to chain several replacements: `caseURL = caseURL.replace("lp_t", "lp_i").replace("Original Format", "1")` – SpghttCd Dec 04 '18 at 12:20

1 Answers1

0

A similar post already exists: How to replace multiple substrings of a string?

You can pick one answer from multiple options in the above post.

ParvBanks
  • 1,316
  • 1
  • 9
  • 15