Op 2005-11-16, Mike Meyer schreef [EMAIL PROTECTED]:
Antoon Pardon [EMAIL PROTECTED] writes:
Op 2005-11-15, Mike Meyer schreef [EMAIL PROTECTED]:
Antoon Pardon [EMAIL PROTECTED] writes:
Like having an assignment operator (let use @= for it) next to a
(re)bind operator.
We could then have
Op 2005-11-15, Bengt Richter schreef [EMAIL PROTECTED]:
On 15 Nov 2005 08:51:59 GMT, Antoon Pardon [EMAIL PROTECTED] wrote:
Op 2005-11-14, Bengt Richter schreef [EMAIL PROTECTED]:
[...]
You may be interested in reviewing
Op 2005-11-15, Mike Meyer schreef [EMAIL PROTECTED]:
Antoon Pardon [EMAIL PROTECTED] writes:
Like having an assignment operator (let use @= for it) next to a
(re)bind operator.
We could then have something like the following.
a = 5
b = a
a @= 7
b == would result in 7.
You've just
Antoon Pardon [EMAIL PROTECTED] writes:
Op 2005-11-15, Mike Meyer schreef [EMAIL PROTECTED]:
Antoon Pardon [EMAIL PROTECTED] writes:
Like having an assignment operator (let use @= for it) next to a
(re)bind operator.
We could then have something like the following.
a = 5
b = a
a @= 7
b ==
Op 2005-11-14, Mike Meyer schreef [EMAIL PROTECTED]:
Antoon Pardon [EMAIL PROTECTED] writes:
Op 2005-11-10, Mike Meyer schreef [EMAIL PROTECTED]:
[Context recovered from top posting.]
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
Daniel Crespo wrote:
Well, I hope that newcomers to Python don't
Op 2005-11-14, Bengt Richter schreef [EMAIL PROTECTED]:
On 14 Nov 2005 11:20:53 GMT, Antoon Pardon [EMAIL PROTECTED] wrote:
Op 2005-11-14, Paul Rubin schreef http:
Antoon Pardon [EMAIL PROTECTED] writes:
We could then have something like the following.
a = 5
b = a
a @= 7
b == would
On 11/14/05, Bengt Richter [EMAIL PROTECTED] wrote:
On 14 Nov 2005 11:20:53 GMT, Antoon Pardon [EMAIL PROTECTED] wrote:
Op 2005-11-14, Paul Rubin schreef http:
Antoon Pardon [EMAIL PROTECTED] writes:
We could then have something like the following.
a = 5
b = a
a @= 7
b == would
On 15 Nov 2005 08:51:59 GMT, Antoon Pardon [EMAIL PROTECTED] wrote:
Op 2005-11-14, Bengt Richter schreef [EMAIL PROTECTED]:
[...]
You may be interested in reviewing
http://groups.google.com/group/comp.lang.python/browse_thread/thread/f96b496b6ef14e2/32d3539e928986b3
before continuing
On Tue, 15 Nov 2005 03:23:11 -0600, Chris Mellon [EMAIL PROTECTED] wrote:
On 11/14/05, Bengt Richter [EMAIL PROTECTED] wrote:
[...]
You may be interested in reviewing
http://groups.google.com/group/comp.lang.python/browse_thread/thread/=
f96b496b6ef14e2/32d3539e928986b3
before continuing
Antoon Pardon [EMAIL PROTECTED] writes:
Like having an assignment operator (let use @= for it) next to a
(re)bind operator.
We could then have something like the following.
a = 5
b = a
a @= 7
b == would result in 7.
You've just overwritten the object referred to by the token 5 in the
Op 2005-11-10, Mike Meyer schreef [EMAIL PROTECTED]:
[Context recovered from top posting.]
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
Daniel Crespo wrote:
Well, I hope that newcomers to Python don't confuse himselves :)
This mutable/immutable object and name/variable is confusing.
Only if
Antoon Pardon [EMAIL PROTECTED] writes:
We could then have something like the following.
a = 5
b = a
a @= 7
b == would result in 7.
Ouch! :-(((
Can't you live with
a = [5]
b = a
a[0] = 7
so b[0] is now 7.
--
http://mail.python.org/mailman/listinfo/python-list
Op 2005-11-14, Paul Rubin schreef http:
Antoon Pardon [EMAIL PROTECTED] writes:
We could then have something like the following.
a = 5
b = a
a @= 7
b == would result in 7.
Ouch! :-(((
Can't you live with
a = [5]
b = a
a[0] = 7
so b[0] is now 7.
And what do I have to do, in case
Antoon Pardon [EMAIL PROTECTED] writes:
Op 2005-11-10, Mike Meyer schreef [EMAIL PROTECTED]:
[Context recovered from top posting.]
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
Daniel Crespo wrote:
Well, I hope that newcomers to Python don't confuse himselves :)
This mutable/immutable object
On 14 Nov 2005 11:20:53 GMT, Antoon Pardon [EMAIL PROTECTED] wrote:
Op 2005-11-14, Paul Rubin schreef http:
Antoon Pardon [EMAIL PROTECTED] writes:
We could then have something like the following.
a = 5
b = a
a @= 7
b == would result in 7.
Ouch! :-(((
Can't you live with
a = [5]
b
Bengt Richter wrote:
You may be interested in reviewing
http://groups.google.com/group/comp.lang.python/browse_thread/thread/f96b496b6ef14e2/32d3539e928986b3
before continuing this topic ;-)
Interesting indeed, I mean the argument of why python does it this way.
I see the equivalent
On Mon, 14 Nov 2005 09:53:34 -0500, Mike Meyer [EMAIL PROTECTED] wrote:
Antoon Pardon [EMAIL PROTECTED] writes:
Op 2005-11-10, Mike Meyer schreef [EMAIL PROTECTED]:
[Context recovered from top posting.]
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
Daniel Crespo wrote:
Well, I hope that
On Thu, 10 Nov 2005 06:47:41 +, Donn Cave wrote:
Quoth Steven D'Aprano [EMAIL PROTECTED]:
...
| So when working with ints, strs or other immutable objects, you aren't
| modifying the objects in place, you are rebinding the name to another
| object:
|
| py spam = a tasty meat-like food
Op 2005-11-10, Steven D'Aprano schreef [EMAIL PROTECTED]:
On Thu, 10 Nov 2005 06:47:41 +, Donn Cave wrote:
Quoth Steven D'Aprano [EMAIL PROTECTED]:
...
| So when working with ints, strs or other immutable objects, you aren't
| modifying the objects in place, you are rebinding the name to
Antoon Pardon wrote:
Write somekind of property so that if you manipulate a.x it would
manipulate data[-1]
Like that?
def make_prp(index):
... def get(self): return self[index]
... def set(self, value): self[index] = value
... return property(get, set)
...
class List(list):
...
Hi
Proposition 1:
data = [0, None, 2, 0]
ref = data[-1]
ref = 1
assert data[-1] == 1
Logically, it doesn't work. Here you are assigning to ref a NEW value.
That won't replace the data[-1] value. It's out of logic this
proposition.
While this (proposition 2):
data = [0, None, 2, [hello]]
ref
This mutable/immutable object and name/variable is confusing.
Daniel Crespo wrote:
Well, I hope that newcomers to Python don't confuse himselves :)
Daniel
--
http://mail.python.org/mailman/listinfo/python-list
[Context recovered from top posting.]
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
Daniel Crespo wrote:
Well, I hope that newcomers to Python don't confuse himselves :)
This mutable/immutable object and name/variable is confusing.
Only if you have to overcome a conviction that variables behave
After one knows the characteristic, it is no problem. But judging from
the frequency of the same issue coming up from time to time, it does
confuse people coming from certain programming background.
Mike Meyer wrote:
Only if you have to overcome a conviction that variables behave in a
different
In article [EMAIL PROTECTED], Mike Meyer [EMAIL PROTECTED]
wrote:
...
Most OO languages do the name/variable thing, but some of the popular
ones aren't consistent about it, giving some types special status,
so that sometimes a = b causes b to be copied onto a, and sometimes
it causes a to
On Thu, 10 Nov 2005 08:19:36 -0800, [EMAIL PROTECTED] wrote:
This mutable/immutable object and name/variable is confusing.
It is a source of confusion to newbies, because it is a distinction that
may not be intuitively obvious, and it is a programming model that isn't
quite the same as many
Quoth Steven D'Aprano [EMAIL PROTECTED]:
...
| So when working with ints, strs or other immutable objects, you aren't
| modifying the objects in place, you are rebinding the name to another
| object:
|
| py spam = a tasty meat-like food
| py alias = spam # both names point to the same str object
Isn't there an easier way than
lst[len(lst) - 1] = ...
?
--
http://mail.python.org/mailman/listinfo/python-list
Or alternatively:
Is there a way to make reference to the last element of a list, to use
as a shorthand:
ref := lst[len(lst) - 1] # I know syntax is wrong, but you get the
idea
and then using the last element of the list by (assuming the element is
a dict):
ref[foo] = 42
ref[bar] = Ni!
etc.
I knew there was an easy way :)
Just to satisfy my curiousity: Is there a way to do something like the
reference solution I suggest above?
--
http://mail.python.org/mailman/listinfo/python-list
Aloha,
[EMAIL PROTECTED] wrote:
Isn't there an easier way than
lst[len(lst) - 1] = ...
lst[-1] = ...
Wishing a happy day
LOBI
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
Just to satisfy my curiousity: Is there a way to do something like the
reference solution I suggest above?
No. You cannot overload assignment.
Of course, for mutable objects you can use the object as the reference to
itself.
Peter
--
what do you mean by alias ?
a = b
now both a and b refers to the same object.
[EMAIL PROTECTED] wrote:
So there is no way in Python to make an alias for an object?
/David
--
http://mail.python.org/mailman/listinfo/python-list
I just want an alias. Ideally, I don't want to deal with pointers or
special reference types etc. After all, this is not C++ :)
I just want to be able to make a reference to any old thing in Python.
A list, an integer variable, a function etc. so that I, in complicated
cases, can make a
But if lst[42][pos] happens to hold an integer value, then
a = lst[42][pos]
will _copy_ that integer value into 'a', right? Changing 'a' will not
change the value at lst[42][pos]
--
http://mail.python.org/mailman/listinfo/python-list
On 8 Nov 2005 01:12:07 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
I knew there was an easy way :)
Just to satisfy my curiousity: Is there a way to do something like the
reference solution I suggest above?
If the last element in the list was a dict, then you could do something like
Peter Otten wrote:
[EMAIL PROTECTED] wrote:
Just to satisfy my curiousity: Is there a way to do something like the
reference solution I suggest above?
No. You cannot overload assignment.
I have the impression that this is not an issue, to overload assignments,
which btw. *can* be
On 8 Nov 2005 01:43:43 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
But if lst[42][pos] happens to hold an integer value, then
a = lst[42][pos]
will _copy_ that integer value into 'a', right? Changing 'a' will not
change the value at lst[42][pos]
Right, but try an example:
lst =
Jerzy Karczmarczuk wrote:
Peter Otten wrote:
[EMAIL PROTECTED] wrote:
Just to satisfy my curiousity: Is there a way to do something like the
reference solution I suggest above?
No. You cannot overload assignment.
I have the impression that this is not an issue, to overload
If you want to do what you want(though I don't know why without a
concrete example), just store a mutable object at lst[42][pos], like
this :
lst[42][pos] = [1]
a = lst[42][pos]
a[0] = 2
assert(lst[42][pos][0] == 2)
[EMAIL PROTECTED] wrote:
But if lst[42][pos] happens to hold an integer value,
On 8 Nov 2005 01:43:43 -0800, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
But if lst[42][pos] happens to hold an integer value, then
a = lst[42][pos]
will _copy_ that integer value into 'a', right?
Nope. It will bind the name 'a' to the integer object.
Changing 'a' will not
change the
[EMAIL PROTECTED] wrote:
I just want an alias. Ideally, I don't want to deal with pointers or
special reference types etc. After all, this is not C++ :)
I just want to be able to make a reference to any old thing in Python.
A list, an integer variable, a function etc. so that I, in
Peter Otten wrote cites me:
I have the impression that this is not an issue, to overload assignments,
which btw. *can* be overloaded, but the absence of *aliasing*
(undiscriminate handling of pointers) in Python. Am I wrong?
I think so.
a = b
will always make a a reference to (the same
So there is no way in Python to make an alias for an object?
/David
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 08 Nov 2005 10:25:21 -, Jerzy Karczmarczuk
[EMAIL PROTECTED] wrote:
Would you please concentrate on - what I underlined - the sense of C
aliasing,
where you can make a pointer to point to anything, say, the 176th byte
of a
function code?
Pretty much everything is referred
[EMAIL PROTECTED] wrote:
I just want an alias.
What you want is impossible. But there are many workarounds.
I just want to be able to make a reference to any old thing in Python.
A list, an integer variable, a function etc. so that I, in complicated
cases, can make a shorthand. If myRef
Jerzy Karczmarczuk wrote:
Sure, I didn't want to claim that the assignment a=anything can be plainly
overloaded.
I interpreted your previous post as such a claim. No disagreement here then.
Would you please concentrate on - what I underlined - the sense of C
aliasing, where you can make a
On Tue, 08 Nov 2005 01:31:31 -0800, [EMAIL PROTECTED] wrote:
So there is no way in Python to make an alias for an object?
Yes, sort of. Bind two names to the same mutable object:
py x = [Something mutable]
py y = x
py y.append(this way comes.)
py print x
['Something mutable', 'this way
On Tue, 08 Nov 2005 01:04:13 -0800, [EMAIL PROTECTED] wrote:
Or alternatively:
Is there a way to make reference to the last element of a list, to use
as a shorthand:
ref := lst[len(lst) - 1] # I know syntax is wrong, but you get the
idea
and then using the last element of the list by
On Tue, 08 Nov 2005 01:43:43 -0800, [EMAIL PROTECTED] wrote:
But if lst[42][pos] happens to hold an integer value, then
a = lst[42][pos]
will _copy_ that integer value into 'a', right? Changing 'a' will not
change the value at lst[42][pos]
Not quite. Don't think of Python names as being
[EMAIL PROTECTED] wrote:
Is there a way to make reference to the last element of a list, to use
as a shorthand:
Yes. It's not wise to use, since this is brittle and will fail hard for you,
but since you're interested, this is how you /could/ do it: (largely)
# First of all create a mechanism
51 matches
Mail list logo