Text archives Help
- From: James Bigler <bigler@cs.utah.edu>
- To: "'manta@sci.utah.edu'" <manta@sci.utah.edu>
- Subject: [Manta] Manta like call backs in python
- Date: Tue, 05 Feb 2008 15:07:11 -0700
I discovered variable length parameters for python. This lets you do fun
stuff similar to the callbacks in Manta:
def partial(func, *args):
# Need to rename these args to make them accessible to the child function
creation_time_args = args
def callme(*args):
return apply(func, args + creation_time_args )
return callme
def callback(arg1):
print "arg1 = %s" % arg1
def callback2(arg1, arg2):
print "arg1 = %s, arg2 = %s" % (arg1, arg2)
>>> cb = partial(callback, 2)
>>> cb()
arg1 = 2
>>> cb = partial(callback)
>>> cb(3)
arg1 = 3
>>> cb = partial(callback2)
>>> cb(1,2)
arg1 = 1, arg2 = 2
>>> cb = partial(callback2, 4)
>>> cb(3)
arg1 = 3, arg2 = 4
>>> cb = partial(callback2, 5, 6)
>>> cb()
arg1 = 5, arg2 = 6
I thought it was cool.
James
- [Manta] Manta like call backs in python, James Bigler, 02/05/2008
Archive powered by MHonArc 2.6.16.