[Image-SIG] Scaling image pixels by a variable amount.

Fredrik Lundh fredrik@pythonware.com
Sat, 2 Mar 2002 19:46:58 +0100


> But this doesn't work -- lambda defines a function, and
> therefore a new name space -- and remember that Python
> namespaces do not nest!

they do, in 2.2 and later -- and in 2.1, if you switch
it on:

http://www.python.org/doc/2.1.2/ref/nested-scopes.html

> Thus, we can only use S if it's
> global, e.g.:
> 
> def return_scaled_image( S ):
> global S_g
> S_g = S
> im.point( lambda x : x * S_g )
> return im

before 2.2, the standard pydiom was to explicitly bind the
value to an argument:

    def return_scaled_image(S):
        return im.point( lambda x, S=S: x * S )

cheers /F