0

Python's str.replace seems to be doing "clever" character escaping and the docs don't show any way to 'override' this behaviour.

Expected:

x = "val|with|pipe"

x.replace("|","\|")
>>> "val\|with\|pipe"

Actual output:

x.replace("|","\|")
>>> "val\\|with\\|pipe"

Bonus Round:

x.replace('|','\\|')
>>> "val\\|with\\|pipe"
Bolster
  • 7,460
  • 13
  • 61
  • 96

0 Answers0