On Thu, Dec 31, 2009 at 12:18 PM, Stephen Hansen wrote:
> Hmm? Just use a sentinel which /can't/ exist in the list: then its truly
> safe. If the list can contain all the usual sort of sentinels (False, None,
> 0, -1, whatever), then just make a unique one all your own.
> sentinel = object()
> if
On Thu, Dec 31, 2009 at 1:54 AM, Peter Otten <__pete...@web.de> wrote:
> Somewhat related in 2.6 there's the next() built-in which accepts a default
> value. You can provide a sentinel and test for that instead of using
> try...except:
Thanks. This can be useful in some of the simpler cases. As yo
On Wed, Dec 30, 2009 at 4:01 PM, Steven D'Aprano
wrote:
> On Wed, 30 Dec 2009 15:18:11 -0800, Tom Machinski wrote:
>> Bottom line, I'm going to have to remove this pattern from my code:
>>
>> foo = (foo for foo in foos if foo.bar).next()
>
> I don't
Thanks for the comment and discussion guys.
Bottom line, I'm going to have to remove this pattern from my code:
foo = (foo for foo in foos if foo.bar).next()
I used to have that a lot in cases where not finding at least one
valid foo is an actual fatal error. But using StopIteration to signal
In most cases, `list(generator)` works as expected. Thus,
`list()` is generally equivalent to `[]`.
Here's a minimal case where this equivalence breaks, causing a serious
and hard-to-detect bug in a program:
>>> def sit(): raise StopIteration()
...
>>> [f() for f in (lambda:1, sit, lambda:2
On Mon, Jul 21, 2008 at 3:53 PM, DaveM <[EMAIL PROTECTED]> wrote:
> On Mon, 21 Jul 2008 03:18:01 +0200, Michiel Overtoom <[EMAIL PROTECTED]>
> wrote:
>
>
> >Many major text/word processing programs (Emacs, vi, MS-Word) are also
> >written in C.
>
> I thought Emacs was written in Lisp.
Large part
Hi there,
I'm developing web applications in Python, so I use a templating system to
produce HTML.
We're dealing with heavy traffic here, so my original choice was the fast
and efficient Cheetah. The main problem is that Cheetah doesn't provide
clear error messages. Even in the best cases, you on