At Thursday 2/11/2006 19:23, SpreadTooThin wrote:
I realize I may be beating a dead horse here... but...
def fn(x):
x = x + 1
print x
a = 2
fn(a)
>>> 3
print a
>>> 2
So in some cases the it is safe to assume that your variables to
function will not
change in other cases it is not.. but t
SpreadTooThin wrote:
> Bruno Desthuilliers wrote:
>
>>SpreadTooThin a écrit :
>>
>>>Bruno Desthuilliers wrote:
>>>
>>>
Nick Vatamaniuc a écrit :
(snip)
>In Python all the primitives are copied and all other entities are
>references.
Plain wrong. There's no "prim
Bruno Desthuilliers wrote:
> SpreadTooThin a écrit :
> > Bruno Desthuilliers wrote:
> >
> >>Nick Vatamaniuc a écrit :
> >>(snip)
> >>
> >>>In Python all the primitives are copied and all other entities are
> >>>references.
> >>
> >>Plain wrong. There's no "primitives" (ie : primitive data types)
SpreadTooThin a écrit :
> Bruno Desthuilliers wrote:
>
>>Nick Vatamaniuc a écrit :
>>(snip)
>>
>>>In Python all the primitives are copied and all other entities are
>>>references.
>>
>>Plain wrong. There's no "primitives" (ie : primitive data types) in
>>Python, only objects. And they all get pas
On Wed, Nov 01, 2006 at 12:20:36PM -0800, SpreadTooThin wrote:
>
> Bruno Desthuilliers wrote:
> > Nick Vatamaniuc a �crit :
> > (snip)
> > > In Python all the primitives are copied and all other entities are
> > > references.
> >
> > Plain wrong. There's no "primitives" (ie : primitive data types
SpreadTooThin wrote:
>> Plain wrong. There's no "primitives" (ie : primitive data types) in
>> Python, only objects. And they all get passed the same way.
>
> so..
> def fn(x):
>x = x + 1
>print x
>
> a = 2
> fn(a)
> fn(2)
>
> Wouldn't you say that this is being passed by value rather t
SpreadTooThin schrieb:
> Bruno Desthuilliers wrote:
>> Nick Vatamaniuc a écrit :
>> (snip)
>>> In Python all the primitives are copied and all other entities are
>>> references.
>> Plain wrong. There's no "primitives" (ie : primitive data types) in
>> Python, only objects. And they all get passed
Bruno Desthuilliers wrote:
> Nick Vatamaniuc a écrit :
> (snip)
> > In Python all the primitives are copied and all other entities are
> > references.
>
> Plain wrong. There's no "primitives" (ie : primitive data types) in
> Python, only objects. And they all get passed the same way.
so..
def fn
Nick Vatamaniuc a écrit :
(snip)
> In Python all the primitives are copied and all other entities are
> references.
Plain wrong. There's no "primitives" (ie : primitive data types) in
Python, only objects. And they all get passed the same way.
--
http://mail.python.org/mailman/listinfo/python-l
SpreadTooThin wrote:
[...]
> I don't understand why python would insist that everything must be a
> refrence...
We can tell that :)
> It is of course helpful sometime but other times its not... and now
> I'm sorta out
> of luck...
There are very good reasons for Python's namespace model. Sure i
SpreadTooThin wrote:
> Every time I pass a variable now I will worry that it will be changed
> by the function...
why? who's writing those scary functions that you cannot trust? and
what makes you think they won't abuse any immutable data you give them?
--
http://mail.python.org/mailman/li
At Tuesday 31/10/2006 14:16, SpreadTooThin wrote:
I don't understand why python would insist that everything must be a
refrence...
It is of course helpful sometime but other times its not... and now
I'm sorta out
of luck...
I don't know how to make this structure immutable... Pickle it? Seems
> I don't know how to make this structure immutable... Pickle
> it? Seems very inefficient to me...
Well, classes can be made mostly immutable by intercepting the
attempts to write to it...something like
class Foo(object):
def __setattr__( self, name, val ):
raise TypeError("I'm
J. Clifford Dyer wrote:
> SpreadTooThin wrote:
> > J. Clifford Dyer wrote:
> >> SpreadTooThin wrote:
> >>> Steven D'Aprano wrote:
> On Mon, 30 Oct 2006 13:10:47 -0800, SpreadTooThin wrote:
>
>
> >>> I seems that some of the objects in the list don't get along well with
> >>> deep co
J. Clifford Dyer wrote:
> Thanks, that's very helpful. Playing with your code a bit, I narrowed
> the problem down to the array.array() structure. Looking at
> help(array), there's a method defined called __deepcopy__, which, it
> seems, takes no arguments, while deepcopy is passing it one argum
SpreadTooThin wrote:
> J. Clifford Dyer wrote:
>> SpreadTooThin wrote:
>>> Steven D'Aprano wrote:
On Mon, 30 Oct 2006 13:10:47 -0800, SpreadTooThin wrote:
>>> I seems that some of the objects in the list don't get along well with
>>> deep copy..
>>> See my second example post that us
At Monday 30/10/2006 20:37, Nick Vatamaniuc wrote:
In Python all the primitives are copied and all other entities are
references.
What do you mean?
primitives==builtin classes?
entities==objects?
In Python, objects are never automatically copied, either builtin or
user-defined. Even 123 is a
J. Clifford Dyer wrote:
> SpreadTooThin wrote:
> > Steven D'Aprano wrote:
> >> On Mon, 30 Oct 2006 13:10:47 -0800, SpreadTooThin wrote:
> >>
> > How do I specify or create deep copies of objects that may contain
> > other objects that may contain other object that may contain other
> >
I think you are afraid of references because you are not trusting your
own code. You are afraid it will do "magic" behind the scenes and mess
everything up. One way around that is to simply write better code and
test often.
If everything was copied when passed around it would be pretty awful --
i
SpreadTooThin wrote:
> Steven D'Aprano wrote:
>> On Mon, 30 Oct 2006 13:10:47 -0800, SpreadTooThin wrote:
>>
> How do I specify or create deep copies of objects that may contain
> other objects that may contain other object that may contain other
> objects
See the `copy` module
Steven D'Aprano wrote:
> On Mon, 30 Oct 2006 13:10:47 -0800, SpreadTooThin wrote:
>
> >> > How do I specify or create deep copies of objects that may contain
> >> > other objects that may contain other object that may contain other
> >> > objects
> >>
> >> See the `copy` module especially `cop
On Mon, 30 Oct 2006 13:10:47 -0800, SpreadTooThin wrote:
>> > How do I specify or create deep copies of objects that may contain
>> > other objects that may contain other object that may contain other
>> > objects
>>
>> See the `copy` module especially `copy.deepcopy()`.
>>
>
> This appears t
Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, SpreadTooThin
> wrote:
>
> > I'm really worried that python may is doing some things I wasn't
> > expecting... but lets see...
>
> Expect that Python never copies something if don't ask explicitly for a
> copy.
>
> > if I pass a list to a f
Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, SpreadTooThin
> wrote:
>
> > I'm really worried that python may is doing some things I wasn't
> > expecting... but lets see...
>
> Expect that Python never copies something if don't ask explicitly for a
> copy.
>
> > if I pass a list to a f
SpreadTooThin wrote:
> I'm really worried that python may is doing some things I wasn't
> expecting... but lets see...
>
> if I pass a list to a function def fn(myList):
>
> and in that function I modify an element in the list, then does the
> callers list get modied as well.
>
> def fn(list):
I am no Python guru - just an ordinary user.
There is nothing "scary" about this. There are (many) situations where
this is actually *desirable* but of course there are (many) situations
where this is an unwelcomed side-effect.
In situations where I don't want this to happen, I simply pass down
On 2006-10-30, SpreadTooThin <[EMAIL PROTECTED]> wrote:
> def fn(list):
>list[1] = 0
>
> myList = [1, 2, 3]
> print myList
> fn(myList)
> print myList
>
[1,2,3]
[1,0,3]
>
> How can I avoid this? In this case this is a really simplified
> example but the effects are the same... How do
In <[EMAIL PROTECTED]>, SpreadTooThin
wrote:
> I'm really worried that python may is doing some things I wasn't
> expecting... but lets see...
Expect that Python never copies something if don't ask explicitly for a
copy.
> if I pass a list to a function def fn(myList):
>
> and in that function
I'm really worried that python may is doing some things I wasn't
expecting... but lets see...
if I pass a list to a function def fn(myList):
and in that function I modify an element in the list, then does the
callers list get modied as well.
def fn(list):
list[1] = 0
myList = [1, 2, 3]
print
29 matches
Mail list logo