About 144,000 results
Open links in new tab
  1. How to use string.replace() in python 3.x - Stack Overflow

    Feb 26, 2012 · The string.replace() is deprecated on python 3.x. What is the new way of doing this?

  2. python - How to replace multiple substrings of a string ... - Stack ...

    198 You could just make a nice little looping function. def replace_all(text, dic): for i, j in dic.iteritems(): text = text.replace(i, j) return text where text is the complete string and dic is a …

  3. python .replace () regex - Stack Overflow

    118 In order to replace text using regular expression use the re.sub function: sub (pattern, repl, string [, count, flags]) It will replace non-everlaping instances of pattern by the text passed as …

  4. Python: replacing a function within a class of a module

    May 30, 2018 · 38 I'm trying to replace a function defined within a class in order to modify its function (as in inner workings) without changing the actual code. I've never done this before, …

  5. Python replace string pattern with output of function

    Sep 26, 2012 · I have a string in Python, say The quick @red fox jumps over the @lame brown dog. I'm trying to replace each of the words that begin with @ with the output of a function that …

  6. Python unittest: replace (or patch) a function via mock

    Jan 10, 2021 · I simply replace a function before a test and set it back to the original one at the tests end - without using unittest.mock. The question is how can I replace the function or …

  7. python - Case insensitive replace - Stack Overflow

    May 28, 2009 · 7 This function uses both the str.replace() and re.findall() functions. It will replace all occurences of pattern in string with repl in a case-insensitive way. def replace_all(pattern, …

  8. Replace special characters in a string in Python

    55 str.replace is the wrong function for what you want to do (apart from it being used incorrectly). You want to replace any character of a set with a space, not the whole set with a single space …

  9. python - How can I use a dictionary to do multiple search-and …

    Dec 21, 2022 · I would suggest to use a regular expression instead of a simple replace. With a replace you have the risk that subparts of words are replaced which is maybe not what you want.

  10. python - Python3 mock replace function with another function

    Dec 23, 2019 · How do I mock a function with another function in python, that will also provide a mock object? I have code that does something like: def foo(arg1, arg2): r = bar(arg1) # does …