S
Steve Holden
+1000Gerard said:+1 !!
+1000Gerard said:+1 !!
Please don't assume I was trying to support you. Your remarks showedAlf said:* Steve Holden: [...]Well that's my point, and thanks for backing me up on that : it'sAlf:
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.
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.
considerable ignorance of issue that were extremely nuanced. Whatever
point you were trying to make was lost in your self-aggrandizing
disrespect of Fredrik Lundh, a software engineer of some repute with a
long history of contribution to Python. The fact that your post was
basically a restatement of one of the several competing positions in
that thread makes it no more right than any of the others.
Why thank you for the education. Somehow in my 40-odd years of
programming I had quite overlooked that fact. Which helps how?
Which IMHO you have done little to assist. Just how exactly *do* we
succeed in asking you not to discuss something?
T said:Oops, this one was my fault - the object I was having the issues with
was actually a shelve file, not a dictionary..so just re-assigning the
variable isn't working, but re-writing the object to the shelve file
does. So in this case, is there any way to just change a single
value, or am I stuck rewriting the entry?
Either open the shelve with writeback=True or rewrite the entry.
Rewriting the entry isn't hard: you can just re-use the same value:
def changevalue():
for key in mytest.keys():
temp = mytest[key]
temp.param3 = "newvalue"
mytest[key] = temp
If you really are changing every item in the shelve using writeback=True
will be much simpler, but if you are only changing a few then just tell the
shelve that you've updated them as above.
In Pascal it's x^.Steven said:How do I get a pointer in pure Python code (no ctypes)? I tried both
Pascal and C syntax (^x and *x), but both give syntax errors.
[snip]Alf said:* Steve Holden:Please don't assume I was trying to support you. Your remarks showedAlf said:* Steve Holden: [...]
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.
considerable ignorance of issue that were extremely nuanced. Whatever
point you were trying to make was lost in your self-aggrandizing
disrespect of Fredrik Lundh, a software engineer of some repute with a
long history of contribution to Python. The fact that your post was
basically a restatement of one of the several competing positions in
that thread makes it no more right than any of the others.
What on Earth are you babbling about?
Perhaps next you'll drag in the Pope, saying I've shown him some
disrespect.
News for you: the Pope ain't participating.
* Chris Rebert:
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.
Am 08.02.10 02:51, schrieb Alf P. Steinbach:
Whao. You just needed 10 words, plus a paragraph to explain something in
terms of a spec that's just about 600 pages strong. Amazing display of
conciseness, and certainly the most valuable thing for some programming
newbie to work with. Thanks!
Must. Resist. Ad hominem.
10 words _plus_ an understanding of Java.
P.S. I couldn't resist.
Bruce would be less confusing.Stephen said:On Mon, Feb 8, 2010 at 6:42 PM, Steve Holden <[email protected]
Stephen Hansen wrote:
[...]P.S. I couldn't resist.
And here I was, sitting on my hands ... but someone was wrong on the
Internet, so D'Aprano had to put them right. Your fatal weakness.
Of course this won't make the slightest difference. "'When I use a
word,' said Humpty ..."
This is getting out of hand.
First, someone thought I was you.
Now you think I'm D'Aprano.
I'm just gonna go by Bob for now on.
--B
[snip]
To say, "pass by value" implies things to people. It describes a sort of
world where I'm a function about to do some work, and on my desk I have
a series of boxes with names on it. It describes an environment where
someone comes over and drops something into each of my boxes. The
contents of these boxes are mine alone!
... a += a
... return a
...[1, 1]test1 = 1
test2 = doit(test1)
test1 1
test2 2
test3 = [1]
test4 = doit(test3)
test3 [1, 1]
test4
I know you already know this, but the point is: you're -hurting- other
peoples understanding by using terms like this that don't apply to
Python's specific nature.
I apologize for assuming that "pointer" is a known word to [c.l.p.]
denizens.
I apologize for assuming that "pointer" is a known word to [c.l.p.]
denizens.
It is irrelevant.
Python calls Python functions by associating argument objects (or
objects derived therefrom) with paramenter names, very much like
assigment statements.
If one understands Python objects, names, and assignment statements,
which one must to understand Python, this completely explains the
function calls, function execution, and its effect on passed objects.
All Python expressions evaluate to an object. Call expressions evaluate
to the object returned by the function.
Different interpreters implement call and return differently. Certainly,
most humans do not use C pointers when they mentally execute Python code.
* Stephen Hansen -> Alf P. Steinbach:[snip]
To say, "pass by value" implies things to people. It describes a sort
of world where I'm a function about to do some work, and on my desk I
have a series of boxes with names on it. It describes an environment
where someone comes over and drops something into each of my boxes. The
contents of these boxes are mine alone!
Then, when the imprecision makes people misunderstand, one should not
say that.
One should then be more precise.
One should say /what/ is passed by value.
The terms apply very well to Java. And Java has the identical parameter
passing mechanism for class type objects. Hence, the argument is bogus.
Isn't Bruce a shark? http://www.imdb.com/character/ch0003722/ andI've heard that, and can't fathom the claim. I've only ever met a single
Bruce in my entire life, though I've seen a couple on the 'net. Maybe its
geographical, and Bruce's just don't like California? I dunno.
On Mon, Feb 8, 2010 at 8:01 PM, Alf P. Steinbach <[email protected]
* Stephen Hansen -> Alf P. Steinbach:
[snip]
To say, "pass by value" implies things to people. It describes a
sort of world where I'm a function about to do some work, and on
my desk I have a series of boxes with names on it. It describes
an environment where someone comes over and drops something into
each of my boxes. The contents of these boxes are mine alone!
Then, when the imprecision makes people misunderstand, one should
not say that.
One should then be more precise.
One should say /what/ is passed by value.
No.
One should not use the phrase that is fundamentally imprecise.
The phrase "pass by value" means something different then the phrase
"pass by object" aka "pass by sharing". They are in many cases very
similar. They are not the same.
Using it is simply wrong. There is
really no legitimate argument you can make otherwise: even in languages
where call-by-value IS the norm, the phrase is imprecise enough to
confuse people, as the semantics of what call-by-value mean to a
language vary. But those semantics do NOT apply to Python.
[snip]
I know you already know this, but the point is: you're -hurting-
other peoples understanding by using terms like this that don't
apply to Python's specific nature.
The terms apply very well to Java. And Java has the identical
parameter passing mechanism for class type objects. Hence, the
argument is bogus.
[1] Java uses silly terminology; and that it chooses to use silly
terminology in no way impacts the validity of the argument. Java isn't
an authority. Python's been around longer! And the specific behavior
here, "call by value where the value is an object reference" was named
"call by sharing" back in the 1970's by Liskov.
Java isn't call-by-value (for objects) either, even if that phrase is
common in the Java community.
C is call-by-value. VB is, I believe,
call-by-value -- though I may be wrong here, as I only sort of blinked
at VB a long, long time ago.
Its distinct. Its different. Its neither call-by-value, nor
call-by-reference. The /value/ of a thing is NOT its identity. Its the
/state/ of that thing.
By your argument, call-by-reference is call-by-value too! Because you're
passing "a value" -- but you're -always- going to pass some piece of
data, otherwise you're not actually passing anything.
The /by value/ vs /by reference/ vs /by sharing/ is not about "is a
value being passed", in all cases, "a value" is. By Value means a copy
of the thing is made. By Reference means you're accessing the callers
variable directly. By Sharing means you're both sharing the same object.
PS: I cannot see any of your postings on Usenet. So I just sort of
grabbed this from GMane and posted to Usenet. Hopefully you'll see
it back at the list.
I've heard that before, and have no idea why, nor any real interest in
solving it: I don't want to read cpl via Usenet, and prefer to read it
as a mailing list. Somewhere between Gmail->python.org->python.org
<http://python.org>'s usenet server->the world, some people don't seem
to get my posts. Yet it shows up on some news servers, not others.
No idea. Nothing I know of can solve it.
* Stephen Hansen -> Alf P. Steinbach:Then, when the imprecision makes people misunderstand, one should not[snip]
To say, "pass by value" implies things to people. It describes a sort
of world where I'm a function about to do some work, and on my desk I
have a series of boxes with names on it. It describes an environment
where someone comes over and drops something into each of my boxes. The
contents of these boxes are mine alone!
say that.
One should then be more precise.
One should say /what/ is passed by value.
I don't see how that matters. Python's behaviour is EXACTLY the same, no
matter what you pass to the function.
You don't pass pointers in Python, because you, the Python author, have
no way of specifying a pointer in Python code. It is *always* an object
that you pass, by giving a literal, the name an object is bound to, or
some other expression that returns an object:
function( my_object )
function( 12345 )
function( ham(3) + spam(5) )
If you're talking to the person who writes Python code, then you should
discuss the sorts of things that exist in Python: objects and names and
expressions, but no pointers.
If you're talking about the Python virtual machine, instead of the high-
level Python code, then you should say so -- but there are still no
pointers in the VM. Look at the output of dis.dis and you will see
objects pushed onto a stack, but no pointers.
It's not until you get past the level of Python code, past the virtual
machine, and into the implementation of the virtual machine, that you
will finally find pointers.
But why stop there? If somebody asks you a question about Python, and you
choose to ignore them and answer a different question about one
particular implementation's internals instead, I don't see why you stop
there. Why not go down another layer and talk about copying bytes, or two
layers and answer that Python does call-by-bit-flipping, or a layer below
that and say it's all done by varying potential differences?
You shouldn't expect your listener to understand machine code to
understand Python's high-level behaviour, nor should you expect them to
be C coders. You don't need to understand pointers to understand a
language that doesn't support them.
Java programmers suffer for a bad mental model just as much as Python
programmers.
All this is because of two conceptual mistakes: (1) the Java community
has conflated the internals of what happens in the implementation of the
Java VM with high-level Java code; and (2) a refusal to accept that there
are calling strategies other than pass-by-value and pass-by-reference.
You don't have anything /but/ pointers in Python.
x = 5
y = "hello"
You want us to accept that the values of x and y are some mysterious
pointer entities rather than the integer object 5 and the string object
"hello".
At the point that your explanation depends on the reader understanding
that the value of a variable x is not actually the thing that they assign
to x, but some mysterious, invisible entity that exists entirely inside
the implementation where the user can never reach, you probably should
rethink your attachment to that explanation. No wonder so many Java
programmers are still confused by it.
It might help your case if we had a word for the thing that is actually
assigned to the variable. In plain English that is "value", but you want
to use that for the pointer to the thing-that-we-otherwise-would-call-
value, which leaves us no simple way to talk about the int 5 and string
"hello".
Sorry about that, Bob. But you have to admit your pedantry was ratherStephen said:On Mon, Feb 8, 2010 at 6:42 PM, Steve Holden <[email protected]
Stephen Hansen wrote:
[...]P.S. I couldn't resist.
And here I was, sitting on my hands ... but someone was wrong on the
Internet, so D'Aprano had to put them right. Your fatal weakness.
Of course this won't make the slightest difference. "'When I use a
word,' said Humpty ..."
This is getting out of hand.
First, someone thought I was you.
Now you think I'm D'Aprano.
I'm just gonna go by Bob for now on.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.