jeudi 3 mars 2016

How can someone check the entire environment for an identical instance of a class in Python?

I'm creating a program in Python that draws "cards" by creating a random instance of a self-defined Card class (i.e. it randomizes the suit and rank to create a new card).

The problem I'm running into is that it's possible for duplicate cards to be generated, sometimes within the same hand. Is there a built-in or standard function for searching the whole local environment for an identical instance of a class (each attribute has the same value)?

If not, I have defined object equality using __eq__ to mean that the suit and rank are both equal. How can I figure out if a certain class exists within the local() dictionary (or within one of its lists), then pull those instances to determine equality?




Aucun commentaire:

Enregistrer un commentaire