As part of a program I'm making, I have a class, and have 5 different instances of this class declared globally for accessing by anywhere else in the program. The class has a list associated with it, that should be different for each of the 5 instances of the classes.
The Problem:
I have a function within the class that I use to add a line to the list, when I call this, it doesn't just add it to the list in the first instance of the class, it also adds it to the second instance for some strange reason (but it doesn't add it to any of the other 3 instances of this class). Here is the code below:
# For storing information about auctions
class AuctionList:
def __init__(self):
self.auctionData = [] # Unique to each instance
# Add an auction to the list
def Add_Auction(self,temp_auction):
print self
print "add before"
print "currentAuctionsListGLOBAL.Get_Num_Auctions():",currentAuctionsListGLOBAL.Get_Num_Auctions()
print "previousCurrentAuctionListGLOBAL.Get_Num_Auctions():",previousCurrentAuctionListGLOBAL.Get_Num_Auctions()
print "finishedAuctionListGLOBAL.Get_Num_Auctions():",finishedAuctionListGLOBAL.Get_Num_Auctions()
self.auctionData.append(temp_auction)
print "add after"
print "currentAuctionsListGLOBAL.Get_Num_Auctions():",currentAuctionsListGLOBAL.Get_Num_Auctions()
print "previousCurrentAuctionListGLOBAL.Get_Num_Auctions():",previousCurrentAuctionListGLOBAL.Get_Num_Auctions()
print "finishedAuctionListGLOBAL.Get_Num_Auctions():",finishedAuctionListGLOBAL.Get_Num_Auctions()
def Get_Num_Auctions(self):
return len(self.auctionData)
# 5 Instances of this glass for global access
currentAuctionsListGLOBAL = AuctionList()
fixedPriceOfferAuctionListGLOBAL = AuctionList()
previousCurrentAuctionListGLOBAL = AuctionList()
finishedAuctionListGLOBAL = AuctionList()
successfulAuctionListGLOBAL = AuctionList()
Above is the class, and where the 5 instances are declared.
Below is how I call the Add function above, to add a line to one of the class instances.
import auction_list
auction_list.currentAuctionsListGLOBAL.Add_Auction("line to add")
This would then printout to the terminal the following:
<auction_list.AuctionList instance at 0x0000000002FE25C8>
add before
currentAuctionsListGLOBAL.Get_Num_Auctions(): 1
previousCurrentAuctionListGLOBAL.Get_Num_Auctions(): 1
finishedAuctionListGLOBAL.Get_Num_Auctions(): 0
add after
currentAuctionsListGLOBAL.Get_Num_Auctions(): 2
previousCurrentAuctionListGLOBAL.Get_Num_Auctions(): 2
finishedAuctionListGLOBAL.Get_Num_Auctions(): 0
I also have a bit in the main function to print out the memory location so I know
that they are accessing the correct instance of the class they are supposed to:
def Main():
print "curr",currentAuctionsListGLOBAL
print "prev",previousCurrentAuctionListGLOBAL
This prints out:
curr <auction_list.AuctionList instance at 0x0000000002FE25C8>
prev <auction_list.AuctionList instance at 0x000000000300C5C8>
As you can see, when I try to add a line to the class instance currentAuctionsListGLOBAL, it add it to it and previousCurrentAuctionListGLOBAL. But I only want it to be added to the first one currentAuctionsListGLOBAL. I don't understand how it is able to add it to the other? It is using the correct instance for currentAuctionsListGLOBAL, as you can see in the memory location (is that correct terminology?)
Can anyone see my mistake, its really got me stumped. Thx