python - Objects with the same var values seems to be the one object for index() method in List -


so have model card. in project create carddata wrapper of model:

card = card.objects.get(id=someid) carddata = {} carddata.id = card.id carddata.title = card.title 

than put on 30 carddatas in deck list:

deck = [carddata1, carddata2 ..., carddata17] 

finally somewhere in game have link example on cardcata17. contains in deck list. @ same time there carddata2 whith same params becouse created same model. , when try index of carddata17:

index = deck.index(carddata17)  

it return index = 2, , not 17 because carddata 2 has same id , title. rather strange , spend lot of time understand problem. real or mistake in assumption.

make objects of card data instead of dictionaries. objects identified memory location, unique, instead of content.

class carddata(object):   def __init__(self, id, title):     self.id = id     self.title = title  card = card.objects.get(id=someid) carddata = carddata(card.id, card.title) 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -