Skip to content
Advertisement

Tag: replace

String replace doesn’t appear to be working [duplicate]

This question already has answers here: Why doesn’t calling a string method (such as .replace or .strip) modify (mutate) the string? (3 answers) Closed 7 months ago. I initially tried using = operator to assign value but it returned an error, then I tried using string.replace(): and But it is returning the orignal value. Help out as to how to

How to search and replace text in a file?

How do I search and replace text in a file using Python 3? Here is my code: Input file: When I search and replace ‘ram’ by ‘abcd’ in above input file, it works as a charm. But when I do it vice-versa i.e. replacing ‘abcd’ by ‘ram’, some junk characters are left at the end. Replacing ‘abcd’ by ‘ram’ Answer

Advertisement