<div class="gmail_quote">On 28 May 2011 23:18, Patrick Totzke <span dir="ltr"><<a href="mailto:patricktotzke@googlemail.com">patricktotzke@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
if r: #because we cant iterate on NoneType<br></blockquote><div><br></div><div>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.</div><div><br></div>
<div>If you change it to</div><div><br></div><div>if r is not None:</div><div><br></div><div>... then it works for me. </div><div><br></div><div>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:</div>
<div><br></div><div><div> .. note:: As this iterates over the messages, we will not be able to=</div><div> iterate over them again! So this will fail::</div><div><br></div><div> #THIS FAILS</div>
<div> msgs = Database().create_query('').search_message()</div><div> if len(msgs) > 0: #this 'exhausts' msgs</div><div> # next line raises NotmuchError(STATUS.NOT_INITIALIZED)!!!</div>
<div> for msg in msgs: print msg</div><div><br></div><div> Most of the time, using the</div><div> :meth:`Query.count_messages` is therefore more</div><div> appropriate (and much faster). While not guaranteeing</div>
<div> that it will return the exact same number than len(),</div><div> in my tests it effectively always did so.</div></div><div><br></div><div><br></div><div><br></div></div>-- <br>Brian May <<a href="mailto:brian@microcomaustralia.com.au">brian@microcomaustralia.com.au</a>><br>