On 4/21/2016 6:54 PM, Tim Chase wrote:

I'd simplify this code to something like

   class PieceFactory(object):
     @staticmethod
     def factory(color, piece, position):
       try:
         return {
           'Bishop': Bishop,
           'King': King,
           'Knight': Knight,
           'Pawn': Pawn,
           'Queen': Queen,
           'Rook': Rook,
           }[piece](color, position)
       except KeyError:
         raise PieceException(...)

I like this better. I'll probably remove the try/except and let the KeyError filter up.

Thanks,

Chris R.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to