Re: scope of function parameters
- From: Terry Reedy <tjreedy@xxxxxxxx>
- Date: Sun, 29 May 2011 18:20:30 -0400
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
.
- Prev by Date: Re: Beginner needs advice
- Next by Date: Re: How to Use Setuptools, Alternatives?
- Previous by thread: Re: scope of function parameters
- Next by thread: Error: child process close a socket inherited from parent
- Index(es):
Relevant Pages
|