-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparagraph.py
32 lines (24 loc) · 911 Bytes
/
paragraph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import random
class Paragraph(object):
def __init__(self, phrase="", positions=0):
self._phrases = [phrase]
self._positions = int(positions)
self._phrase = phrase
def add_phrase(self, phrase):
self._phrases.append(phrase)
self._phrase = random.choice(self._phrases)
def __str__(self):
return self._phrase
def get_inserts(self):
return self._phrase
def get_slots(self):
return self._phrase.count("%s")
def get_parsed_content(self, subs=()):
if (self.get_slots() == 0):
return (self._phrase + '\n')
elif (self.get_slots() == len(subs)):
return ((self._phrase) % (subs)) + '\n'
elif (self.get_slots() == 1):
return ((self._phrase) % (subs[0])) + '\n'
else:
return (self._phrase + '\n')