Re: scope of function parameters



On 5/29/2011 4:19 PM, Henry Olders wrote:

From my perspective, a function parameter should be considered as
having been assigned (although the exact assignment will not be known
until runtime), and as an assigned variable, it should be considered
local.

That is exactly the case for Python functions.

>>> def f(a,b):
c,d = 3,4
print(locals())

>>> f.__code__.co_varnames # local names
('a', 'b', 'c', 'd')
>>> f(1,2)
{'a': 1, 'c': 3, 'b': 2, 'd': 4}

The requirement for a function call is that all parameters get an assignment and that all args are used in assignments (either directly by position or keyname or as part of a *args or **kwds assignment).

--
Terry Jan Reedy

.