What am I doing wrong?

keithlackey keithlackey at deegroup.com
Wed Sep 21 02:12:12 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?




More information about the Python-list mailing list