class / instance question

belinda thom bthom at cs.hmc.edu
Fri Mar 23 03:01:27 CET 2007


Hello,

I'm hoping the Python community knows whether or not the following is  
possible, and if it is possible, how I would go about writing code to  
do this.

I've written two game classes---Nim and TicTacToe---where each  
derives from a Game class that I've created (it is essentially an  
abstract base class, where I've used an "abstract()" hack to somewhat  
enforce this).

I now want to be able to pass either of these classes into a game- 
playing engine, for instance a function

playGame(classOfGameToBePlayed) :

    # inside of which I create a new game using that class's constructor

Is this possible, and if so, how to approach it?

Thanks a lot,

--b



More information about the Python-list mailing list