Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6706 > unrolled thread
| Started by | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| First post | 2011-05-30 22:20 -0700 |
| Last post | 2011-05-30 22:20 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: scope of function parameters (take two) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-05-30 22:20 -0700
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2011-05-30 22:20 -0700 |
| Subject | Re: scope of function parameters (take two) |
| Message-ID | <mailman.2299.1306819808.9059.python-list@python.org> |
On Mon, 30 May 2011 20:28:34 -0400, Henry Olders
<henry.olders@mcgill.ca> declaimed the following in
gmane.comp.python.general:
>
> What I would like is that the variables which are included in the function definition's parameter list, would be always treated as local to that function (and of course, accessible to nested functions) but NOT global unless explicitly defined as global. This would prevent the sort of problems that I encountered as described in my original post. I may be wrong here, but it seems that the interpreter/compiler should be able to deal with this, whether the parameter passing is by value, by reference, by object reference, or something else. If variables are not assigned (or bound) at compile time, but are included in the parameter list, then the binding can be made at runtime.
But "names" in a parameter list ARE local to the body of the
function... Binding a new value to that name has no effect outside the
body.
Mutating the contents of a container type that is associated with
that name is a different matter.
a = [1, 2, 3]
def sample(x):
x[1] = "me" #mutates the [1] element of whatever x is associated
with
x = "you" #rebinds the name x to a new value which disconnects
#from the object originally associated to x
sample(a)
# a is now [1, "me", 3], not "you"
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to top | Article view | comp.lang.python
csiph-web