full closures

Michael P. Soulier msoulier at nortelnetworks.com_.nospam
Wed Feb 27 13:34:23 EST 2002


    Hello. 

    While I know about bound methods in Python, I'm wondering if a full
closure can be implemented. Can it?

    Example: I want to pass an arbitrary code reference into a closure and
have all of its variables preserved. 

    ie. 

    print "the current count is %d" % counter; counter += 1

    Can I pass the above code into a closure, and then simply call it
repeatedly and see counter increment itself? If I pass in a function with a
local variable, that local will be reset each time, and I don't want to use a
global. 

    Thanks,

    Mike

-- 
Michael P. Soulier, QX41, SKY  Tel: 613-765-4699 (ESN: 39-54699)
Optical Networks, Nortel Networks, SDE Pegasus
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort."  -Harley Hahn, A Student's Guide to Unix



More information about the Python-list mailing list