* Steve Holden:
Alf P. Steinbach wrote:
* MRAB:
Alf P. Steinbach wrote:
* Chris Rebert:
On Sun, Feb 7, 2010 at 5:05 PM, T <misceveryth...@gmail.com> wrote:
Ok, just looking for a sanity check here, or maybe something I'm
missing. I have a class Test, for example:
class Test:
def __init__(self, param1, param2, param3):
self.param1 = param1
self.param2 = param2
self.param3 = param3
Next, I have a dictionary mytest that contains instances of Test. If
I want to modify one of the Test instances within my dictionary, I
have to rewrite the entire entry, correct (since Python passes by
value, not reference)?
Incorrect; Python uses neither. See
http://effbot.org/zone/call-by-object.htm for a excellent explanation
of what Python does use.
Hm. While most everything I've seen at effbot.org has been clear and
to the point, that particular article reads like a ton of obfuscation.
Python passes pointers by value, just as e.g. Java does.
There, it needed just 10 words or so. :-) Or perhaps some more words
to point out that in the Java language spec those reference values
are called pointers, but that this terminology isn't (apparently)
used for Python, and isn't even well known among Java programmers.
But that's just one extra little para.
One just has to be clear about exactly what it is that's passed by
value.
Not Python objects, but references (pointers) to them, the id(o) values.
A reference is not the same as a pointer.
Depends on your choice terminology. I referred to the Java (language
spec) terminology to make it clear.
A pointer tells you where something is; a reference doesn't.
Sorry, I don't know of any relevant terminology where that is the case.
Alf:
This topic was discussed at great, nay interminable, length about a year
ago. I'd appreciate it if you would search the archives and read what
was said then rather than hashing the whole topic over again to nobody's
real advantage.
Well that's my point, and thanks for backing me up on that :-): it's very
simple, and as demonstrated can be expressed in 10 words or less (plus perhaps a
terminology reference, as I did above), so all that discussion and in particular
the lengthy article at effbot serves as obfuscation and nothing else.
By the way, most every programming language has some corner like that, something
that is utterly simple but somehow has some kind of obfuscation-meme attached.
In C++ it's "call" and "constructor". It doesn't help that the language's
standard lays down the law on it, it doesn't help that the language's creator
has laid down the law, it doesn't help that it's utterly and completely simple.
Somehow newbies and even some experienced people manage to create their own
terminological nightmare and drawing conclusions about reality from that
misguided obfuscated view, and then discussing it up and down and sideways.
Cheers & hth.,
- Alf
--
http://mail.python.org/mailman/listinfo/python-list