i face that problem in my code.Anyone can help me for solving that problem
class RegexpReplacer(object):
def __init__(self, patterns=replacement_patterns):
self.patterns = [(re.compile(regex), repl) for (regex, repl) in
patterns]
def replace(self, text):
s = text
for (pattern, repl) in self.patterns:
s = re.sub(pattern, repl, s)
return s
from replacers import RegexpReplacer
replacer = RegexpReplacer()
print(replacer.replace("can't is a contraction"))
error is ModulueNotFound error
ModuleNotFoundError: No module named 'replacers'
答案 0 :(得分:2)
首先,请确保使用命令pip install replacer
安装替换程序。其次,从您的代码中删除from replacers import RegexpReplacer
。在您的代码中的某个地方,缩进存在问题。请尝试给出的代码。这样可以解决您的问题。
class RegexpReplacer(object):
def __init__(self, patterns=replacement_patterns):
self.patterns = [(re.compile(regex), repl) for (regex, repl) in patterns]
def replace(self, text):
s = text
for (pattern, repl) in self.patterns:
s = re.sub(pattern, repl, s)
return s
replacer=RegexpReplacer()
print(replacer.replace("can't is a contradicton"))