This question is similar to this except that the substring to be replaced is only known at the runtime.
I want to write the definition of ireplace
, that behaves like this:
>>> ireplace(r'c:\Python26\lib\site.py', r'C:\python26', r'image\python26')
r'image\python26\lib\site.py'
>>>