Finding the instance reference of an object

Arnaud Delobelle arnodel at googlemail.com
Sat Nov 8 14:07:07 CET 2008


On Nov 8, 6:21 am, greg <g... at cosc.canterbury.ac.nz> wrote:
> Arnaud Delobelle wrote:
> > 'Pass by value' is not relevant to Python as variables do not contain
> > anything.
>
> Where abouts in the phrase "pass by value" does the word
> "contain" appear?

You don't quote enough context for it to appear.
> You don't need a notion of containment in order for
> "pass by value" to have meaning. All you need is some
> notion of a "value" (it doesn't matter what) and
> some way to "pass" that value.
>
> > 'Pass by reference' is not relevant to Python as the language
> > doesn't have the concept of object reference (in the sense of e.g. C++
> > reference).
>
> What it doesn't have is the concept of a *variable*
> reference, which is what the "reference" in "pass by
> reference" means.

What's a variable reference?

> > Here lies, IMHO, the reason why you think you need Python to 'pass by
> > value'.  As you believe that variables must contain something, you think
> > that assignment is about copying the content of a variable.  Assignment
> > in Python is simply giving a new name to an object.
>
> Yes, and so is passing by value!

What you're saying is that in the code below, when foo(q) is called
then 'p' in foo is another name for q in main. Right?

struct point {
    int x;
    int y;
}

int foo(point p) {
    p.x = 42;
}

int main() {
    point q = {0, 0};
    foo(q);
    /* So now you're saying that q.x == 0 ? */
}

--
Arnaud




More information about the Python-list mailing list