Why this error message
Ryan Kelly
ryan at rfk.id.au
Sun Jan 31 15:53:00 EST 2010
On Sun, 2010-01-31 at 15:25 -0500, Ray Holt wrote:
> 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
Based on the indentation, it looks like you've defined "test" as a
method on the SpecialFile class. Try dedenting it to begin in the first
column.
Ryan
--
Ryan Kelly
http://www.rfk.id.au | This message is digitally signed. Please visit
ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/python-list/attachments/20100201/00135386/attachment-0001.sig>
More information about the Python-list
mailing list