Passing Values

mike.mellor at tbe.com mike.mellor at tbe.com
Tue Feb 13 07:49:32 EST 2001


I am working on an RPN calculator program, using a four level stack.  
I initialize it as:

stack = [0.0,0.0,0.0,0.0]

I am noticing problems with the following two functions (xStack and 
yStack are Entry widgets).  clearer is supposed to clear the values 
of the stack, and RollDown is supposed to "roll the stack" down.

def clearer(event):
    yStack.delete(0,END)
    xStack.delete(0,END)
    stack = [0.0, 0.0, 0.0, 0.0]
    print 'Clear ' + str(stack)
    for i in range(4):
       print 'Stack ' + `i` + ' ' + str(stack[i])

def RollDown(event):
    stack[0] = stack[1]
    stack[1] = stack[2]
    stack[2] = stack[3]
    try:
        stack[3] = float(xStack.get())
    except ValueError:
        stack[3] = 0.0
    xStack.delete(0,END)
    xStack.insert(0,stack[0])
    yStack.delete(0,END)
    yStack.insert(0,str(stack[1]))
    print 'Roll down ' + str(stack)
    for i in range(4):
       print 'Stack ' + `i` + ' ' + str(stack[i])

The console reports that the stack is cleared, but when I roll the 
stack down, old values pop in.  Do I need to use a deepcopy to pass 
the values from one stack location to the next (stack[0] = deepcopy
(stack[1])) or is there a better way to do this?

Thanks.

Mike






More information about the Python-list mailing list