How much sanity checking is required for function inputs?

Ethan Furman ethan at stoneleaf.us
Sun Apr 24 10:41:43 EDT 2016


On 04/23/2016 06:00 PM, Christopher Reimer wrote:
> Hmm... What do we use Enum for? :)

from enum import Enum
class Piece(Enum):
 king = 'one space, any direction'
 queen = 'many spaces, any direction'
 bishop = 'many spaces, diagonal'
 knight = 'two spaces cardinal, one space sideways, cannot be blocked'
 rook = 'many spaces, cardinal'
 pawn = 'first move: one or two spaces forward; subsequent moves: 
one space forward; attack: one space diagonal'
--> list(Piece)
[
 <Piece.king: 'one space, any direction'>,
 <Piece.queen: 'many spaces, any direction'>,
 <Piece.bishop: 'many spaces, diagonal'>,
 <Piece.knight: 'two spaces cardinal, one space sideways, cannot be 
blocked'>,
 <Piece.rook: 'many spaces, cardinal'>,
 <Piece.pawn: 'first move: one or two spaces forward; subsequent 
moves: one space forward; attack: one space diagonal'>,
 ]
--> p = Piece.bishop
--> p in Piece
True
--> p is Piece.rook
False
--> p is Piece.bishop
True
--
~Ethan~


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /