makeReplacer¶
- emlib.textlib.makeReplacer(conditions)[source]¶
Create a function to replace many subtrings at once
- Parameters:
conditions (
dict) – a dictionary mapping a string to its replacement- Return type:
Callable- Returns:
a function to be called to produce the given transformation
Example
Create a function to remove some unwanted characters
>>> import emlib.textlib >>> replacer = emlib.textlib.makeReplacer({"[": "", "]": "", '"': '', "'": "", "{": "", "}": ""}) >>> replacer("[foo:'{bar}']") foo:bar