Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 95727431FD0 for ; Tue, 31 May 2011 22:35:39 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VUTZKYIGCkoc for ; Tue, 31 May 2011 22:35:37 -0700 (PDT) Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 4B4AB431FB6 for ; Tue, 31 May 2011 22:35:37 -0700 (PDT) Received: by bwg12 with SMTP id 12so4795130bwg.26 for ; Tue, 31 May 2011 22:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microcomaustralia.com.au; s=google; h=domainkey-signature:mime-version:x-originating-ip:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=pZHC8uqvQZee5XReK4U8LuXTkm+Rz8mOwycGQf+YVbU=; b=W5vQ+2KisPe7G7EMCuJm3mFuoJWQ9D7kkY6qPZSyDxcHAIpoRTcPCmnZ4R5YoyKm8Q lzTbMOioVtIeDeW8q3loZGacDxfS6m63qcp3V6xuogxCAPX/P9pd36MJ0AAx4Xof6mSG wUw1QEBRFXf5TipBA68H9O/Ez6Bayvfa09FoI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=microcomaustralia.com.au; s=google; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; b=bnwzHsdSUwplVXB5Xy/Sjo0xx7fK9olrQDLnGSg3uPXjZQ4EdLV1Q/nqNU4WRAFx0U 3UZtOykLORTH7eI0HRP3UKQoujkkfXREdJjuRthNytoVlCYcRm6O0MxIz6cIUZvb2i/C aYeN4KvDUn3hBeNFbHesW3bVLVd8N8FzpuBtA= MIME-Version: 1.0 Received: by 10.204.172.66 with SMTP id k2mr6239203bkz.125.1306906535558; Tue, 31 May 2011 22:35:35 -0700 (PDT) Received: by 10.204.82.147 with HTTP; Tue, 31 May 2011 22:35:35 -0700 (PDT) X-Originating-IP: [128.250.103.228] In-Reply-To: <1306588052-sup-9838@brick> References: <1306588052-sup-9838@brick> Date: Wed, 1 Jun 2011 15:35:35 +1000 Message-ID: Subject: Re: [python] get all messages of a thread From: Brian May To: Patrick Totzke Content-Type: multipart/alternative; boundary=bcaec52c5c8dce7d8804a49fe3bc Cc: notmuch X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Jun 2011 05:35:39 -0000 --bcaec52c5c8dce7d8804a49fe3bc Content-Type: text/plain; charset=ISO-8859-1 On 28 May 2011 23:18, Patrick Totzke wrote: > if r: #because we cant iterate on NoneType > I don't understand why, but this line sets r._msgs to None. So it crashes, because it has no message ids to look for. If you change it to if r is not None: ... then it works for me. Oh, I see, for your code, there is a implied call to __len__, and the __len__ function is completely broken for the reasons described in the documentation: .. note:: As this iterates over the messages, we will not be able to= iterate over them again! So this will fail:: #THIS FAILS msgs = Database().create_query('').search_message() if len(msgs) > 0: #this 'exhausts' msgs # next line raises NotmuchError(STATUS.NOT_INITIALIZED)!!! for msg in msgs: print msg Most of the time, using the :meth:`Query.count_messages` is therefore more appropriate (and much faster). While not guaranteeing that it will return the exact same number than len(), in my tests it effectively always did so. -- Brian May --bcaec52c5c8dce7d8804a49fe3bc Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On 28 May 2011 23:18, Patrick Totzke <patricktotzke@= googlemail.com> wrote:
=A0 =A0if r: #because we cant iterate on NoneType

=
I don't understand why, but this line sets r._msgs to None. = So it crashes, because it has no message ids to look for.

If you change it to

if r is not None:

... then it works for me.=A0

Oh,= I see, for your code, there is a implied call to __len__, and the __len__ = function is completely broken for the reasons described in the documentatio= n:

=A0 =A0 =A0 .. note:: As this iterates over the me= ssages, we will not be able to=3D
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= iterate over them again! So this will fail::

=A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#THIS FAILS
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0msgs =3D Database().create_query(&#= 39;').search_message()
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if = len(msgs) > 0: =A0 =A0 =A0 =A0 =A0 =A0 =A0#this 'exhausts' msgs<= /div>
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# next line raises Not= muchError(STATUS.NOT_INITIALIZED)!!!
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0for msg in msgs: print msg<= /div>

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Most of the time, u= sing the
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0:meth:`Query.count_messag= es` is therefore more
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0appropriate = (and much faster). While not guaranteeing
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0that it will return the exact same numb= er than len(),
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0in my tests it effe= ctively always did so.



--
Brian May <brian@microcomaustralia.com.au>
--bcaec52c5c8dce7d8804a49fe3bc--