Re: [Tutor] The trap of the year

2011-01-26 Thread ALAN GAULD
> When I read your tutorial I was probably blind... :-D > I am going to re-read it. Actually I don't think I discuss it. I only mention default arguments very briefly because they are not a standard programming feature. My tutor tries to teach general programming not Python specifics so it d

Re: [Tutor] The trap of the year

2011-01-25 Thread Corey Richardson
On 01/25/2011 06:49 PM, Steven D'Aprano wrote: > Corey Richardson wrote: > >> To be pedantic, a method _is_ a function, just under the umbrella of a >> class, with it's parent object being passed to it. > > To be even more pedantic, a method object is a wrapper (technically, a > descriptor) aroun

Re: [Tutor] The trap of the year

2011-01-25 Thread Karim
Sorry Alan, When I read your tutorial I was probably blind... :-D I am going to re-read it. Regards Karim On 01/26/2011 01:30 AM, Alan Gauld wrote: "Karim" wrote If I understand a little bit what happen in: def __init__(self, parameters=[]): [...] The list argument is built before in

Re: [Tutor] The trap of the year

2011-01-25 Thread Karim
After one 2 months of python intensive development. I made this init defaults error in my db classes constructors... Shame on me :-[ Steven ! Your example shows me obvious. Regards Karim On 01/26/2011 12:33 AM, Steven D'Aprano wrote: Karim wrote: Hello All, Just to share on rageous bug

Re: [Tutor] The trap of the year

2011-01-25 Thread Karim
Thanks for the tip Steven. Regards Karim On 01/26/2011 12:39 AM, Steven D'Aprano wrote: Karim wrote: Hello Bob, I know this fact for function but in this case this is not a function but a constructor method of a class. Methods *are* functions. (Technically, they are lightweight wrappers

Re: [Tutor] The trap of the year

2011-01-25 Thread Alan Gauld
"Karim" wrote If I understand a little bit what happen in: def __init__(self, parameters=[]): [...] The list argument is built before instance creation and indeed constructor execution. So this is the same list instance of constructor parameter for all new instance creation. Yes that

Re: [Tutor] The trap of the year

2011-01-25 Thread Steven D'Aprano
Corey Richardson wrote: To be pedantic, a method _is_ a function, just under the umbrella of a class, with it's parent object being passed to it. To be even more pedantic, a method object is a wrapper (technically, a descriptor) around a function object. It's also slightly different between

Re: [Tutor] The trap of the year

2011-01-25 Thread Steven D'Aprano
Karim wrote: Hello Bob, I know this fact for function but in this case this is not a function but a constructor method of a class. Methods *are* functions. (Technically, they are lightweight wrappers around functions.) They are treated exactly the same by Python. The "constructor method" _

Re: [Tutor] The trap of the year

2011-01-25 Thread Steven D'Aprano
Karim wrote: Hello All, Just to share on rageous bug I encounter where 2 lists which "should" to be different (same id) because hold by different instances of the same class are not in fact DIFFERENT, see below: I think you are confused. If the two lists have the same ID, they should be th

Re: [Tutor] The trap of the year

2011-01-25 Thread Karim
Yes you're right. But the class and instance thing made me believe the context would be different. Error of judgment. Regards Karim On 01/25/2011 10:57 PM, Corey Richardson wrote: On 01/25/2011 04:28 PM, Karim wrote: Hello Bob, I know this fact for function but in this case this is not a f

Re: [Tutor] The trap of the year

2011-01-25 Thread Corey Richardson
On 01/25/2011 04:28 PM, Karim wrote: > > Hello Bob, > > I know this fact for function but in this case this is not a function > but a constructor method of a class. To be pedantic, a method _is_ a function, just under the umbrella of a class, with it's parent object being passed to it. ~Corey >

Re: [Tutor] The trap of the year

2011-01-25 Thread Karim
On 01/25/2011 10:12 PM, Jerry Hill wrote: On Tue, Jan 25, 2011 at 3:41 PM, Karim > wrote: I am not really understanding why my init in the class made it refers to the same list object. What is the difference with 2nd example directly at the prompt? See

Re: [Tutor] The trap of the year

2011-01-25 Thread Karim
Hello Bob, I know this fact for function but in this case this is not a function but a constructor method of a class. The impact is not the same because all instance share the same argument parameter.This a kind of singleton argument :-) . I believed that the constructor will create each time

Re: [Tutor] The trap of the year

2011-01-25 Thread bob gailer
On 1/25/2011 3:41 PM, Karim wrote: Hello All, Just to share on rageous bug I encounter where 2 lists which "should" to be different (same id) because hold by different instances of the same class are not in fact DIFFERENT, see below: >>> class Device(): ... def __init__(self, parameters

Re: [Tutor] The trap of the year

2011-01-25 Thread Karim
If I understand a little bit what happen in: def __init__(self, parameters=[]): [...] The list argument is built before instance creation and indeed constructor execution. So this is the same list instance of constructor parameter for all new instance creation. For me it was a bad surpri

Re: [Tutor] The trap of the year

2011-01-25 Thread Izz ad-Din Ruhulessin
Or the internal memory id or whatever it's called. 2011/1/25 Izz ad-Din Ruhulessin > I think it has something to do with the physical id of the object > > 2011/1/25 Karim > > >> Hello All, >> >> Just to share on rageous bug I encounter where 2 lists which "should" to >> be different (same id) b

Re: [Tutor] The trap of the year

2011-01-25 Thread Jerry Hill
On Tue, Jan 25, 2011 at 3:41 PM, Karim wrote: > I am not really understanding why my init in the class made it refers to > the same list object. > What is the difference with 2nd example directly at the prompt? > See http://effbot.org/zone/default-values.htm -- Jerry __

Re: [Tutor] The trap of the year

2011-01-25 Thread Izz ad-Din Ruhulessin
I think it has something to do with the physical id of the object 2011/1/25 Karim > > Hello All, > > Just to share on rageous bug I encounter where 2 lists which "should" to be > different (same id) because hold by different instances of the same class > are not in fact DIFFERENT, see below: > >

[Tutor] The trap of the year

2011-01-25 Thread Karim
Hello All, Just to share on rageous bug I encounter where 2 lists which "should" to be different (same id) because hold by different instances of the same class are not in fact DIFFERENT, see below: >>> class Device(): ... def __init__(self, parameters=[]): ... self.parameters =