What am i doing Wrong?

keithlackey keithlackey at deegroup.com
Wed Sep 21 02:16:55 EDT 2005


I'm relatively new to python and I've run into this problem.
 
 
DECLARING CLASS
 
      class structure:
            def __init__(self, folders = []):        
                  self.folders = folders
        
      def add_folder(self, folder):
            self.folders.append(tuple(folder))
 
 
 
Now I try to make an instance of this class
 
      structure1 = structure()
      structure1.add_folder([('foo'),])
      print structure1.folders
 
This returns: [('foo',)]
 
This works fine. But when I try to make another instance of that class...
 
      structure2 = structure()
      print structure2.folders
 
This now also returns: [('foo',)]
Even though I haven't added any folders to this new instance
 
What am I doing wrong?
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050921/6409d467/attachment.html>


More information about the Python-list mailing list