Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6588

Re: scope of function parameters

From Terry Reedy <tjreedy@udel.edu>
Subject Re: scope of function parameters
Date 2011-05-29 18:20 -0400
References <F8395F78-615E-4FBD-B6FC-1D6173EAEA45@mcgill.ca> <201105291147.26545.wolfgang@rohdewald.de> <371A067F-540A-46C3-820C-4348B9815AB9@mcgill.ca>
Newsgroups comp.lang.python
Message-ID <mailman.2241.1306707648.9059.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: scope of function parameters Terry Reedy <tjreedy@udel.edu> - 2011-05-29 18:20 -0400

csiph-web