ClassExample1.py
--D. Thiebaut 02:38, 26 January 2010 (UTC)
#! /usr/bin/python
# D. Thiebaut
# A simple example with classes
# text1 taken from Alice in Wonderland, Mad Tea Party
# text2 taken from Winnie the Pooh
#
text1 = """`Have some wine,' the March Hare said in an encouraging tone.
Alice looked all round the table, but there was nothing on it but tea.
`I don't see any wine,' she remarked.
`There isn't any,' said the March Hare.
`Then it wasn't very civil of you to offer it,' said Alice angrily.
`It wasn't very civil of you to sit down without being invited,'
said the March Hare. """
text2 = """Piglet sidled up to Pooh from behind. "Pooh," he whispered.
"Yes, Piglet?"
"Nothing," said Piglet, taking Pooh's paw,
"I just wanted to be sure of you."
"""
class docuClass:
def __init__( self, doc ):
self.doc = doc
self.lines = doc.split( "\n" )
self.wordCount = len( doc.split() )
def getWordCount( self ):
return self.wordCount
def getLines( self ):
return self.lines
def display( self ):
for line in self.lines:
print line
def main():
doc1 = docuClass( text1 )
doc2 = docuClass( text2 )
print "doc1"
doc1.display()
print "doc2"
doc2.display()
main()