python3中的句子变化

问题描述 投票:-1回答:1

几个月前,我发现了这种语法:

{Hello|Dear} {Customer|client|person},

xxxx

这将生成如下句子:

Hello Customer,

要么

Dear person,

怎么称呼?有没有解析这个的框架?如果没有,我该怎么做?

我打算在构建句子的自动化脚本中使用它。

还有什么进一步的想法,我应该使用哪些框架在python中构建句子?当python脚本中嵌入长文本块时,它会产生丑陋的代码。

python python-3.x frameworks pep8 sentence-synthesis
1个回答
0
投票

如果你想随机问候,

import random
greetings = ["hello", "dear"]
print("{} person".format(str(random.choice(greetings))))
© www.soinside.com 2019 - 2024. All rights reserved.