[Tutor] constants, flags or whatever

bhaaluu bhaaluu at gmail.com
Thu Dec 20 03:35:34 CET 2007


This isn't elegant, but it is a start. My method is: get SOMETHING working,
then work from there. 8^D

"""
constant: moving = "m"
constant: inserting = "i"
constant: jumping = "j"
.
.
action = moving
.
.
.
if action == jumping:
    jumpSomewhere()
elseif action == moving:
    moveSomewhere()
elseif action == inserting:
    insertSomething()
"""
##############################
moving = False
inserting = False
jumping = False

def jumpingSomewhere():
    global jumping
    print jumping
    jumping = True
    return jumping

def insertingSomething():
    global inserting
    print inserting
    inserting = True
    return inserting

def movingSomewhere():
    global moving
    print moving
    moving = True
    return moving

jumpingSomewhere()
insertingSomething()
movingSomewhere()

print jumping
print inserting
print moving
#############################

Output:
False
False
False
True
True
True


On Dec 19, 2007 8:44 PM, Jim Morcombe <jmorcombe at westnet.com.au> wrote:
>
>
> In a program, I want to set some kind of variable or object to indicate what
> "mode" the program is currently in.
> What is the most elegant way of doing this?
>
> Jim
> ---------------------------------------------------------------------------
> constant: moving = "m"
> constant: inserting = "i"
> constant:jumping = "j"
> .
> .
> action = moving
> .
> .
> .
> if action == jumping:
>         jumpSomewhere()
> elseif action == moving:
>         moveSomewhere()
> elseif action == inserting:
>         insertSomething()
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>



-- 
b h a a l u u at g m a i l dot c o m


More information about the Tutor mailing list