On 19/11/2015 19:09, Chris Angelico wrote:
On Fri, Nov 20, 2015 at 5:50 AM, BartC <b...@freeuk.com> wrote:
But you're not going to tell me what it is I got wrong!

I said that Python's "=" does a very shallow copy. And I stated that in A=B,
something of B must be copied into A.

I (and probably others) would like to know why none of that is correct. But
I suspect I'm not wrong.

There's no copying happening. You evaluate the expression `B`, and get
back some kind of object (because all expressions in Python evaluate
to objects, unless they raise exceptions or in some way don't finish
evaluating). The name A then becomes bound to that object. You're not
copying a reference; you're simply referencing the result of an
expression.

OK, so it's just a coincidence that after A=B, id(A) appears to be an identical copy of id(B)? And which also agrees with my assertions that a very shallow copy is done, and that some aspect of B is duplicated in A.

It is an excellent explanation of the exact points you're confused about.

As far I'm concerned I'm not confused by these copying aspects. I said 'very shallow copy', not 'shallow copy' nor 'deep copy' nor just 'copy'. To me, 'very shallow copy' about sums it up.

While Python byte-code for A=B:

    6 LOAD_GLOBAL              0 (b)
    9 STORE_GLOBAL             1 (a)

doesn't really disagree with me either as it looks remarkably like any other basic copy operation of any machine language or byte-code that has ever been invented.

If you said instead that I'm not using the official jargon then perhaps you're right. But the right terminology isn't going to make me like Python's default values any better!

--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to