Re: [Tutor] Need Explanation...

2011-12-12 Thread Homme, James
ce training. Thanks for your patience. Jim -Original Message- From: tutor-bounces+james.homme=highmark@python.org [mailto:tutor-bounces+james.homme=highmark@python.org] On Behalf Of Alan Gauld Sent: Monday, December 12, 2011 2:58 PM To: tutor@python.org Subject: Re: [Tutor] Need

Re: [Tutor] Need Explanation...

2011-12-12 Thread Alan Gauld
James H wrote: Is that the same problem with using the len function on sequences > and open on files, or is it different? I don't think so. I'm not sure which problem you are referring to with these? Neither return None... But a python list is mutable. I'm hardly an expert, but the idea is

Re: [Tutor] Need Explanation...

2011-12-12 Thread James Reynolds
A() creates an instance of A. But like I said I'm not an expert. > -Original Message- > From: tutor-bounces+james.homme=highmark@python.org > [mailto:tutor-bounces+james.homme=highmark@python.org] On Behalf Of Alan > Gauld > Sent: Saturday, December 10, 2011

Re: [Tutor] Need Explanation...

2011-12-12 Thread Homme, James
...@python.org] On Behalf Of Alan Gauld Sent: Saturday, December 10, 2011 4:16 AM To: tutor@python.org Subject: Re: [Tutor] Need Explanation... On 10/12/11 07:41, sunil tech wrote: > /def app(x):/ > / return x.append(100)/ > / > /p = app(a)/ > / > /now list holds appended val

Re: [Tutor] Need Explanation...

2011-12-11 Thread Sunil Tech
*Thank you all...* *for your previous time. :) * On Sun, Dec 11, 2011 at 2:56 PM, Alan Gauld wrote: > On 11/12/11 03:23, Lie Ryan wrote: > > If returning 'self' is the default expected behavior, it would cause >> inconsistencies with respect to immutable types. For example, `5 >> .__add__(2)`, on

Re: [Tutor] Need Explanation...

2011-12-11 Thread Alan Gauld
On 11/12/11 03:23, Lie Ryan wrote: If returning 'self' is the default expected behavior, it would cause inconsistencies with respect to immutable types. For example, `5 .__add__(2)`, one could expect it to return 5 instead of 7. That's not a case where default behaviour would be invoked. I'm t

Re: [Tutor] Need Explanation...

2011-12-10 Thread Lie Ryan
On 12/11/2011 04:04 AM, Alan Gauld wrote: On 10/12/11 16:46, Steven D'Aprano wrote: circumstances, regardless of which behaviour was choosen for append, it would catch out some people some time. Probably, although if returning 'self' were the default (which of course only makes sense in a pure

Re: [Tutor] Need Explanation...

2011-12-10 Thread ALAN GAULD
>> Smalltalk's mechanism  stands in stark contrast to the mixed >> model in Python. (OTOH Smalltalk overall is a frustrating >> experience for me, I would like to love it but never quite >> get there... :-) > >Personally, I found that returning a copy of a seemed more logical- after all,  >if you

Re: [Tutor] Need Explanation...

2011-12-10 Thread Max gmail
On Dec 10, 2011, at 12:04 PM, Alan Gauld wrote: > On 10/12/11 16:46, Steven D'Aprano wrote: > >> ...the alternative would also have caught out everybody at some point. >> Consider a hypothetical Python where mutator methods returned a result: >> >> a = [1, 2, 3] >> b = a.append(4) >> >> Does t

Re: [Tutor] Need Explanation...

2011-12-10 Thread Alan Gauld
On 10/12/11 16:46, Steven D'Aprano wrote: ...the alternative would also have caught out everybody at some point. Consider a hypothetical Python where mutator methods returned a result: a = [1, 2, 3] b = a.append(4) Does this mean...? * append 4 to a, then return a (and therefore a and b are a

Re: [Tutor] Need Explanation...

2011-12-10 Thread Steven D'Aprano
Alan Gauld wrote: [...] Because app() returns the result of append(). But append() returns None, since it modifies the list in place. This is one of the few features of Python I dislike. It would not have been difficult to make these modifier methods return the thing modified. This style would

Re: [Tutor] Need Explanation...

2011-12-10 Thread Alan Gauld
On 10/12/11 07:41, sunil tech wrote: /def app(x):/ / return x.append(100)/ / /p = app(a)/ / /now list holds appended value [1,2,3,100]/ /but p is empty... why it is?/ Because app() returns the result of append(). But append() returns None, since it modifies the list in place. This is one

Re: [Tutor] Need Explanation...

2011-12-10 Thread Asokan Pichai
On Sat, Dec 10, 2011 at 1:11 PM, sunil tech wrote: > hi, > > Consider a list: a = [1,2,3] > > & a simple function, which when called it will append 100 to the list. > > def app(x): >      return x.append(100) > > p = app(a) > > now list holds appended value [1,2,3,100] > but p is empty... why it i

[Tutor] Need Explanation...

2011-12-09 Thread sunil tech
*hi,* * * *Consider a list: a = [1,2,3]* * * *& a simple function, which when called it will append 100 to the list.* * * *def app(x):* * return x.append(100)* * * *p = app(a)* * * *now list holds appended value [1,2,3,100]* *but p is empty... why it is?* * * *please teach.* ___