On 2/24/2012 8:23 AM, Roy Smith wrote:
In article,
Antoon Pardon wrote:
Python doesn't try to prevent people from shooting themselves in the foot.
Yes it does! A simple example is None as a keyword to prevent
assignments to it.
Hmmm. Just playing around with some bizarre things to do wi
In article ,
Antoon Pardon wrote:
> > Python doesn't try to prevent people from shooting themselves in the foot.
> >
> Yes it does! A simple example is None as a keyword to prevent
> assignments to it.
Hmmm. Just playing around with some bizarre things to do with None, and
discovered thi
Stefan Behnel wrote:
> I know that you just meant this as an example, but it's worth
> mentioning in this context that it's not exactly efficient to "sum up"
> lists this way because there is a lot of copying involved. Each adding
> of two lists creates a third one and copies all elements into it
On 02/24/2012 12:33 AM, Steven D'Aprano wrote:
If your application stops working after you carelessly mess with
components your application relies on, the right answer is usually:
"Don't do that then."
Python doesn't try to prevent people from shooting themselves in the foot.
Yes it does! A
Buck Golemon wrote:
> I feel like the design of sum() is inconsistent with other language
> features of python. Often python doesn't require a specific type, only
> that the type implement certain methods.
>
> Given a class that implements __add__ why should sum() not be able to
> operate on that
On Fri, Feb 24, 2012 at 10:33 AM, Steven D'Aprano
wrote:
> Yes, deleting _sentinel will cause the custom sum to fail, and yes, you
> have missed something.
>
> If the caller wants to mess with your library and break it, they have
> many, many ways to do so apart from deleting your private variable
On Fri, 24 Feb 2012 08:53:49 +1100, Chris Angelico wrote:
> On Fri, Feb 24, 2012 at 8:41 AM, Arnaud Delobelle
> wrote:
>> _sentinel = object()
>>
>> def sum(iterable, start=_sentinel):
>> if start is _sentinel:
>>
>> del _sentinel
>
> Somewhat off-topic: Doesn't the if statement there do a lo
On Fri, Feb 24, 2012 at 9:09 AM, Arnaud Delobelle wrote:
> On 23 February 2012 22:04, Chris Angelico wrote:
>> On Fri, Feb 24, 2012 at 8:59 AM, Arnaud Delobelle wrote:
>>> def sum(iterable, start=_sentinel, _sentinel=_sentinel):
>>
>> Is this a reason for Python to introduce a new syntax, such a
On 23 February 2012 22:04, Chris Angelico wrote:
> On Fri, Feb 24, 2012 at 8:59 AM, Arnaud Delobelle wrote:
>> def sum(iterable, start=_sentinel, _sentinel=_sentinel):
>
> Is this a reason for Python to introduce a new syntax, such as:
>
> def foo(blah, optional=del):
> if optional is del: pri
On Fri, Feb 24, 2012 at 8:59 AM, Arnaud Delobelle wrote:
> def sum(iterable, start=_sentinel, _sentinel=_sentinel):
Is this a reason for Python to introduce a new syntax, such as:
def foo(blah, optional=del):
if optional is del: print("No argument was provided")
Basically, 'del' is treated
On Thu, Feb 23, 2012 at 2:53 PM, Chris Angelico wrote:
> On Fri, Feb 24, 2012 at 8:41 AM, Arnaud Delobelle wrote:
>> _sentinel = object()
>>
>> def sum(iterable, start=_sentinel):
>> if start is _sentinel:
>>
>> del _sentinel
>
> Somewhat off-topic: Doesn't the if statement there do a lookup f
On 23 February 2012 21:53, Chris Angelico wrote:
> On Fri, Feb 24, 2012 at 8:41 AM, Arnaud Delobelle wrote:
>> _sentinel = object()
>>
>> def sum(iterable, start=_sentinel):
>> if start is _sentinel:
>>
>> del _sentinel
>
> Somewhat off-topic: Doesn't the if statement there do a lookup for a
>
On Thu, Feb 23, 2012 at 2:38 PM, Buck Golemon wrote:
> My proposal is still *slightly* superior in two ways:
>
> 1) It reduces the number of __add__ operations by one
> 2) The second argument isn't strictly necessary, if you don't mind
> that the 'null sum' will produce zero.
It produces the wron
On Fri, Feb 24, 2012 at 8:41 AM, Arnaud Delobelle wrote:
> _sentinel = object()
>
> def sum(iterable, start=_sentinel):
> if start is _sentinel:
>
> del _sentinel
Somewhat off-topic: Doesn't the if statement there do a lookup for a
global, which would mean that 'del _sentinel' will cause it to
Chris Rebert, 23.02.2012 22:32:
> On Thu, Feb 23, 2012 at 1:19 PM, Buck Golemon wrote:
>> I feel like the design of sum() is inconsistent with other language
>> features of python. Often python doesn't require a specific type, only
>> that the type implement certain methods.
>>
>> Given a class th
On 23 February 2012 21:23, Buck Golemon wrote:
> def sum(values,
> base=0):
> values =
> iter(values)
>
> try:
> result = values.next()
> except StopIteration:
> return base
>
> for value in values:
> result += value
> return result
This is defi
On Feb 23, 1:32 pm, Chris Rebert wrote:
> On Thu, Feb 23, 2012 at 1:19 PM, Buck Golemon wrote:
> > I feel like the design of sum() is inconsistent with other language
> > features of python. Often python doesn't require a specific type, only
> > that the type implement certain methods.
>
> > Give
On Thu, Feb 23, 2012 at 1:19 PM, Buck Golemon wrote:
> I feel like the design of sum() is inconsistent with other language
> features of python. Often python doesn't require a specific type, only
> that the type implement certain methods.
>
> Given a class that implements __add__ why should sum()
On 23 February 2012 21:19, Buck Golemon wrote:
> I feel like the design of sum() is inconsistent with other language
> features of python. Often python doesn't require a specific type, only
> that the type implement certain methods.
>
> Given a class that implements __add__ why should sum() not be
On Feb 23, 1:19 pm, Buck Golemon wrote:
> I feel like the design of sum() is inconsistent with other language
> features of python. Often python doesn't require a specific type, only
> that the type implement certain methods.
>
> Given a class that implements __add__ why should sum() not be able t
I feel like the design of sum() is inconsistent with other language
features of python. Often python doesn't require a specific type, only
that the type implement certain methods.
Given a class that implements __add__ why should sum() not be able to
operate on that class?
We can fix this in a bac
21 matches
Mail list logo