Module Is Not Callable

beno zope at thewebsons.com
Sat Jan 11 09:54:14 EST 2003


Hi;
I have tested the following script and it works as long as I input it into 
the command prompt. But when I try and write it to a script, then call the 
script, I get the following error:

 >>> import test
 >>> import string
 >>> test()
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: 'module' object is not callable

Why?
TIA,
beno

Script follows...

"""
Testimonials.py
This script turns testimonials in individual files into drop-down select 
style boxes
that can be inserted into HTML pages. Said files must be located in the
*testimonials* folder (within a language folder if using Easy Cart) in your 
Web site
folder. The first line of each such file must contain *only* the name of 
the person
giving the testimony.
"""

import string

class Testimonials:
         count = 0
         lines = []
         allLines = ''
         countOne = 0
         clickForMore = 'no'
         def __init__(self):
                 total = 0
                 name = ''
                 readFile = []
                 self.readFile = open('test1','r')
                 while self.readFile.readline() != '':
                         self.count = self.count + 1
                 self.total = self.count
                 self.readFile.close()
         def firstRead(self):
                 self.readFile = open('test1','r')
                 self.name = self.readFile.readline()
                 self.count = self.count - 1
         def subsequentRead(self):
                 if self.count != 0:
                         self.lines.append(self.readFile.readline())
                         self.count = self.count - 1
                         self.subsequentRead()
                 else:
                         pass
         def firstLine(self):
                 self.allLines += self.lines[0]
         def subsequentLines(self):
                 if self.total > 2:
                         self.total = self.total - 1
                         self.countOne = self.countOne + 1
                         self.allLines += self.lines[self.countOne]
                         self.subsequentLines()
                 else:
                         table = string.maketrans('\n', ' ' )
                         self.allLines = string.translate(self.allLines,table)
         def formatLines(self):
                 wordlist = string.split(self.allLines)
                 ln = []
                 temp = ''
                 i = 0
                 while wordlist != []:
                         while (wordlist != [] and (len(temp) + 
len(wordlist[0])) < 40):
                                 temp = temp + wordlist[0] + ' '
                                 del wordlist[0]
                         ln.append(temp)
                         temp = ''
                         if i == 0:
                                 if self.clickForMore == 'no':
                                         self.theTestimonial = '<select>\n 
<option value="pass">See what ' \
                                                 + self.name[:-1] + ' has 
to say!</option>\n <option ' + \
                                                 'value="pass">&#xa0;</option>\n'
                                 else:
                                         self.theTestimonial = '<select 
name=testimonial onChange="' + \
                                                 'testimonials(this.form)">\n 
<option value="pass">' + 'See what ' \
                                                 + self.name[:-1] + ' has 
to say!</option>\n <option value="pass">' + \
                                                 '&#xa0;</option>\n'
                                 self.theTestimonial += ' <option 
value="pass">' + ln[i] \
                                                         + '</option>\n'
                         else:
                                 self.theTestimonial += ' <option 
value="pass">' + ln[i] + '</option>\n'
                         i += 1
         def endTag(self):
                 if self.clickForMore == 'no':
                         self.theTestimonial += ' <option 
value="pass">&#xa0;</option>\n' + \
                                                 ' <option value="pass">' + 
self.name + '</option>\n</select>'
                 else:
                         self.theTestimonial += ' <option 
value="pass">&#xa0;</option>\n' + \
                                                 ' <option value="pass">' + 
self.name + '</option>\n' + \
                                                 ' <option 
value="pass">&#xa0;</option>\n'
                         self.theTestimonial += ' <option 
value="pass">CLICK FOR MORE' + \
                                                 ' 
TESTIMONIALS!</option>\n</select>'
         def printit(self):
                         print self.theTestimonial

def test():
         f = Testimonials()
         f.firstRead()
         f.subsequentRead()
         f.firstLine()
         f.subsequentLines()
         f.formatLines()
         f.endTag()
         f.printit()









More information about the Python-list mailing list