Which class structure is better for what purposes. This one:
class Text:
def __init__(self, passage):
self.s = passage
def read_text(self):
return self.s
def grow(self, sentence):
self.s = self.s + sentence.s
class Sentence(Text):
def __init__(self, sentence):
Text.__init__(self, sentence)
self.s = sentence
def format(self):
self.s = self.s[:1].title() + self.s[1:len(self.s)-1] + ". "
class Word(Sentence):
def __init__(self, word):
Sentence.__init__(self, word)
self.s = word
def is_word(word, dict):
return word.s in dict
def add_space(self):
self.s = self.s + " "
class Char(Word):
def __init__(self, char):
Word.__init__(self, char)
self.s = char
or this one:
class Text:
def __init__(self, text):
self.t = text
def __str__(self):
return self.t
def is_char(self):
return len(self.t) == 1 and self.t in string.ascii_lowercase
def is_word(self):
return chr(32) not in self.t and chr(44) not in self.t and chr(46) not in self.t
def is_sentence(self):
return self.t[0] in string.ascii_uppercase and self.t[len(self.t)-1] == "."
def not_last_word(self):
return self.t + " "
def grow(self, input):
try:
return self.t + input.t
except:
return self.t + input