Changing global variables in tkinter/pmw callback

Jonathan Claggett jcc.ugm at ix.netcom.com
Fri Apr 6 20:13:16 EDT 2001


Alex wrote:
"...but the resulting confusion between items and attributes seems a strange
target to aim for."

I ought to just admit now to being overly excited by all of python's nifty
extensibility. It IS nifty, so you can hardly expect

Instead, I'll rashly claim that blurring the line between attributes and
hashes is sometimes useful when dealing with a structure whose attributes
you wish to access programmatically. One example might be a doubly linked
list where most of the code accesses the attributes directly but a generic
traverse function uses a parameter to access the attributes. My (trivial)
example:

# normal usage (using Bunch as a structure)
head = Bunch(value="cat", left=None, right=None)
tail = Bunch(value="dog", left=None, right=None)
head.right = tail
tail.left = head

# generic usage (using Bunch as a hash)
def traverse(node, next):
    while node:
        print node.value
        node = node[next]

traverse(head, "right")
traverse(tail, "left")






More information about the Python-list mailing list