Rant (was Re: x*x if x>10

DaveM asma61 at dsl.pipex.com
Sun Jul 27 13:21:43 EDT 2008


On Sun, 27 Jul 2008 16:41:19 +0200, "Diez B. Roggisch" <deets at nospam.web.de>
wrote:


>You obviously aren't aware of the pitfalls regarding the mis-use of or 
>and and for this usage.

<snip example>

Well, yes, I am (and the way around the problem), but as its never caught me
out (so far), I hadn't considered it. 

>Can you tell us what you mean by "several names of one object"? You mean 
>this?
>
>a = range(10)
>b = a
>
>id(a) == id(b)
>
>
>? Passing references instead of values is an extremely important concept 
>of many languages, without it you would end up copying most of the time.

OK. I've obviously been thinking about things the wrong way. In Forth you
pass the memory address around, and presumably that's essentially what's
happening when you pass a reference. The problem is, I get caught frequently
in this situation:

a = [1,2,3]

def foo(x):
	do_something_with_x
	return x

...

Then when I call foo(a), a gets changed. It just isn't the effect I expect
from changing a local.

DaveM



More information about the Python-list mailing list