<div class="gmail_quote"><div class="gmail_quote"><div><div class="h5">On 11 June 2012 08:51, Tom Harris <span dir="ltr"><<a href="mailto:celephicus@gmail.com" target="_blank">celephicus@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Greetings,<br><br>I have a class that implements the iterator protocol, and tokenises a string into a series of tokens. As well as the token, it keeps track of some information such as line number, source file, etc.<br><br>


for tokens in Tokeniser():<br>  do_stuff(token)<br><br>What I want is to be able to wrap the tokeniser to add functionality to the base parser without subclassing, e.g.<br><br>for tokens in processor(Tokeniser()):<br>
  do_stuff(token)<br><br>Sort of Decorator pattern, so that I can chain more processors,  but I cannot think how to implement it. Any clues for me?<br></blockquote><div><br></div></div></div><div>Maybe I've misunderstood. Is this what you're looking for?</div>

<div><br></div><div>def processer(tokens):</div><div>    for token in tokens:</div><div>        yield func(token)</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>Thanks<br><br>TomH<br><br><br>
<br><span class="HOEnZb"><font color="#888888">
<div></div>
<br>--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
<br></font></span></blockquote></div><br>
</div><br>