[Tutor] How to have unique identifiers for multiple object instances of a given class?

boB Stepp robertvstepp at gmail.com
Sun Aug 26 18:38:52 EDT 2018


Python 3.6.6, Linux Mint

I feel that I may be missing something truly obvious.  I am pondering
the design of a solitaire scorekeeper program.  It is just meant to be
an electronic scorekeeper for hands of solitaire that I plan with a
"real" deck of cards, instead of a computer game.  I might want to
play and track a variety of solitaire games.  And I might want to play
one game for a bit and then switch to another.  One version of
solitaire I might play has thirteen possible separately scored
versions, depending on which of thirteen cards gets turned up in the
beginning (2, 3, 4, ... , J, Q, K, A).  So each hand played needs to
be scored under its own card.  I would need to be able to switch back
and forth between all thirteen at need to enter a score for a hand.

So no matter what solitaire game I am playing it seems that it would
boil down to:

class SolitaireGame():
    def __init__(self, name):
        self.name = name

    <The rest of the class to be determined.>

Say I go with the aforementioned game with 13 separate scores to keep
track of.  The names of these games might be "Two_Mastery",
"Three_Mastery", ... , "Ace_Mastery".  In principle I want 13 objects
with each one keeping track of each of the above games.  Then I might
want to switch to "Spider_Solitaire", keep track of its score, then go
to something else, then back to Mastery, etc.  How on earth am I to
generate unique identifiers for each of these SolitaireGame objects in
a rational way, not knowing in advance moment to moment what type of
solitaire game I might be playing?  I am *not* wanting to discard one
object prior to creating a new one for a new game.  I would like to
have all such objects to peacefully coexist and be able to switch
between them at will.  Of course the intent is to persistently store
these objects on disk upon program closure.

TIA!

--
boB


More information about the Tutor mailing list