-1

A few months ago I found something with this kind of syntax:

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

xxxx

This will generate sentences like:

Hello Customer,

or

Dear person,

How is it called? Is there a framework which parses this? If not, how would I do this?

I am planning to use this in an automation script which builds sentences.

Any further idea's on which frameworks I should use for building sentences in python? It makes ugly code when long blocks of text are embedded in python scripts.

VC_work
  • 145
  • 6
  • In python you can perform 'string formatting'. The randomness/choices are done outside of the formatting though. So you can make list of options and pick one randomly. Other option could be to use Jinja2 or other templating framework. – The Pjot Mar 05 '18 at 14:42

1 Answers1

0

If you want random greetings,

import random
greetings = ["hello", "dear"]
print("{} person".format(str(random.choice(greetings))))
Susmit
  • 336
  • 1
  • 4
  • 12
  • Use multiple {} and multiple variables in . format(). s = "{} person good {}". format ("hello", "morning") – Susmit Mar 06 '18 at 14:39