Why this error message

Ray Holt mrholtsr at sbcglobal.net
Sun Jan 31 15:25:57 EST 2010


Why am I getting the error that test is not defined. Thanks, Ray
 class SpecialFile:
    def __init__(self, fileName):
        self.__file = open(fileName, 'W')
        self.__file.write('***** Start Special File *****\n\n')
    def write(self, str):
        self.__file.write(str)
    def writelines(self, strList):
        self.__file.writelines(strList)

    def __del__(self):           # Destructor method, __del__.
        print "entered __del__"    
        self.close()

    def close(self):              # Clean up method
        if self.__file:
            self.__file.write('\\n***** End Special File *****')
            self.__file.close()
            self.__file = None

    def test():
        f = SpecialFile('testfile')
        f.write('111111\n')
        f.close()
test()
Traceback (most recent call last):
  File "C:\Python26\Classes_and_OOP_Programing.py", line 145, in <module>
    test()
NameError: name 'test' is not defined


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100131/4b2f0967/attachment.html>


More information about the Python-list mailing list