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
Mike Meyer wrote:
> Wouldn't one.__dict__ = dict(**two.__dict__) be a bit better?
>
Those stars are redundant here. It would be cleaner to write:
one.__dict__ = dict(two.__dict__)
--
http://mail.python.org/mailman/listinfo/python-list
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.
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 r
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
>>>
>>>
>>> http://groups.google.com/group/comp.lang.py
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
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
>>
>> be
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
>>
>> bef
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 :
> >> Antoon Pardon <[EMAIL PROTECTED]> writes:
> >>> We could then have something like the following.
> >>>
> >>> a = 5
> >>> b = a
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 :
>>> Antoon Pardon <[EMAIL PROTECTED]> writes:
We could then have something like the following.
a = 5
b = a
>
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 tha
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:
>>>
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 equiva
On 14 Nov 2005 11:20:53 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
>Op 2005-11-14, Paul Rubin schreef :
>> 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
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 muta
Op 2005-11-14, Paul Rubin schreef :
> 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
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-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 confu
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 peo
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 caus
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
> differen
[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
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
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"]
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
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 rebindin
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-
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 ob
[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
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 name
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
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
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 ma
[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
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 r
So there is no way in Python to make an alias for an object?
/David
--
http://mail.python.org/mailman/listinfo/python-list
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
[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 co
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
> cha
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 inte
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, t
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:
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*
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 li
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
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 shorthan
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
[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
--
http://mail.python.org/mailm
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
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
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!"
Isn't there an easier way than
lst[len(lst) - 1] = ...
?
--
http://mail.python.org/mailman/listinfo/python-list
52 matches
Mail list logo