[Tutor] constants, flags or whatever

Dave Kuhlman dkuhlman at rexx.com
Thu Dec 20 05:00:04 CET 2007


On Wed, Dec 19, 2007 at 09:41:13PM -0500, bob gailer wrote:

> 1 - I see no value in introducing variables. I'd just use string constants:
> 
> action = "moving"
> .
> .
> if action == "jumping":
> 
> etc.

I agree.  But, some people do prefer something that looks a bit
like an enum.  If so, here is a Python idiom for enums:

Mode_none, Mode_moving, Mode_inserting, Mode_jumping = range(4)

action = Mode_moving

if action == Mode_jumping:
    o
    o
    o

- Dave


-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman


More information about the Tutor mailing list