Re: scared about refrences...

2006-11-02 Thread Gabriel Genellina
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

Re: scared about refrences...

2006-11-02 Thread Steve Holden
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

Re: scared about refrences...

2006-11-02 Thread SpreadTooThin
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)

Re: scared about refrences...

2006-11-02 Thread Bruno Desthuilliers
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

Re: scared about refrences...

2006-11-01 Thread Inyeol Lee
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

Re: scared about refrences...

2006-11-01 Thread Fredrik Lundh
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

Re: scared about refrences...

2006-11-01 Thread Diez B. Roggisch
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

Re: scared about refrences...

2006-11-01 Thread SpreadTooThin
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

Re: scared about refrences...

2006-10-31 Thread Bruno Desthuilliers
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

Re: scared about refrences...

2006-10-31 Thread Steve Holden
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

Re: scared about refrences...

2006-10-31 Thread Fredrik Lundh
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

Re: scared about refrences...

2006-10-31 Thread Gabriel Genellina
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

Re: scared about refrences...

2006-10-31 Thread Tim Chase
> 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

Re: scared about refrences...

2006-10-31 Thread SpreadTooThin
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

Re: scared about refrences...

2006-10-31 Thread Peter Otten
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

Re: scared about refrences...

2006-10-30 Thread J. Clifford Dyer
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

Re: scared about refrences...

2006-10-30 Thread Gabriel Genellina
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

Re: scared about refrences...

2006-10-30 Thread SpreadTooThin
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 > >

Re: scared about refrences...

2006-10-30 Thread Nick Vatamaniuc
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

Re: scared about refrences...

2006-10-30 Thread J. Clifford Dyer
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

Re: scared about refrences...

2006-10-30 Thread SpreadTooThin
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

Re: scared about refrences...

2006-10-30 Thread Steven D'Aprano
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

Re: scared about refrences...

2006-10-30 Thread SpreadTooThin
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

Re: scared about refrences...

2006-10-30 Thread SpreadTooThin
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

Re: scared about refrences...

2006-10-30 Thread Fredrik Lundh
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):

Re: scared about refrences...

2006-10-30 Thread John Henry
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

Re: scared about refrences...

2006-10-30 Thread Neil Cerutti
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

Re: scared about refrences...

2006-10-30 Thread Marc 'BlackJack' Rintsch
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

scared about refrences...

2006-10-30 Thread SpreadTooThin
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