如何替换pyPEG中的一些单词?例如我有一个句子
约翰踢足球
我想把约翰替换成鲍勃,然后写成:
鲍勃踢足球。你知道吗
from pypeg2 import *
class Try(str):
grammar = 'John ', restline
# I am think that here should be same callback function, but i have no idea how to type it
f = parse("John plays football", Try)
print(compose(f))
输出:
John plays football
“John”是第一个被替换的参数,“Bob”是替换字符串。你知道吗
使用
.replace(something, with_something_else)
。你知道吗输出:
相关问题 更多 >
编程相关推荐