Decorator Pattern with Iterator
Tom Harris
celephicus at gmail.com
Mon Jun 11 03:51:11 EDT 2012
Greetings,
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.
for tokens in Tokeniser():
do_stuff(token)
What I want is to be able to wrap the tokeniser to add functionality to the
base parser without subclassing, e.g.
for tokens in processor(Tokeniser()):
do_stuff(token)
Sort of Decorator pattern, so that I can chain more processors, but I
cannot think how to implement it. Any clues for me?
Thanks
TomH
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120611/8d11ffd3/attachment.html>
More information about the Python-list
mailing list