My way is ugly. These has to be a better way.
Thanks,
Gerard
--
http://mail.python.org/mailman/listinfo/python-list
Consider:
>>> def negate(func):
... def wrapper(*args, **kwargs):
... return not func(*args, **kwargs)
... return wrapper
...
>>> def f(x):
... return x > 10
...
>>> g = negate(f)
>>> g(20)
False
>>> g(5)
True
Now g has the argument signature of (*args, **kwargs). Pop-up
Consider:
### Function closure example
def outer(s):
... def inner():
... print s
... return inner
...
>>> f = outer(5)
>>> f()
5
>>> dir(f)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__',
'__get__', '__getattribute__', '__hash__', '__init__', '__module__',
'
I can't solve your problem, but I can at least explain why I think its
hard. foo doesn't have any closed over
variables. Some of its locals have to live in cells, so that pre and
post can see them in their closures.
>>> foo.func_code.co_cellvars
('x', 'y')
Now the only way that I know of to
Consider: A)
>>> class C(object):
... pass
...
>>> def f(*args):
... print args
...
>>> C.f = f
>>> C.f
>>> c=C()
>>> c.f()
(<__main__.C object at 0x04A51170>,)
And B)
>>> del c
>>> C.f = types.MethodType(f, None, C)
>>> C.f
>>> c = C()
>>> c.f()
(<__main__.C object at 0
Is there a way to do:
s = "I like python %i%s of the time."
print s % (99, "%")
without having to pass in "%"?
Thanks,
Gerard
--
http://mail.python.org/mailman/listinfo/python-list
I really don't understand the following behavior:
>>> class C(object):
... def __init__(self, s): self.s = s
... def __str__(self): return self.s
...
>>> cafe = unicode("Caf\xe9", "Latin-1")
>>> c = C(cafe)
>>> print "Print using c.s:", c.s
Print using c.s: Café
>>> print "Print using
Gary Herron wrote:
> Gerard Brunick wrote:
>> I really don't understand the following behavior:
>>
>> >>> class C(object):
>> ... def __init__(self, s): self.s = s
>> ... def __str__(self): return self.s
>> ...
>> >>> ca