[Tutor] Python 2.7.1 interpreter passing function pointer as function argument and Shedskin 0.7

Frank Chang frankchang91 at gmail.com
Wed Dec 29 10:25:50 CET 2010

     I asked the Shedskin developers about this issue and they are currently
adding support for __call__ . They recommend renaming the  class Matcher
__call__ method ,for example as next, and then explicitly call it on line
148 as
     I followed their suggestion and the Shedskin 0.7 Python to C++ compiler
does not complain about the unbound identifier 'lookup_func' anymore.
     I apologize for the cut and paste mangling. Is there a better method
than copy-pasting for including 20 or more lines of python source code in
the tutor posts? Thank you.

           def find_all_matches(self, word, k, lookup_func):
               lev = self.levenshtein_automata(word, k).to_dfa()
               match = lev.next_valid_string('\0')
               while match:
                  follow = lookup_func.test(match)      ### line 148 ###
               if not follow:
               if match == follow:
                  yield match
               follow = follow + '\0'
               match = lev.next_valid_string(follow)

     class Matcher(object):
         def __init__(self, l):
            self.l = l
            self.probes = 0
         def test(self, w):
            self.probes += 1
            pos = bisect.bisect_left(self.l, w)
            if pos < len(self.l):
                return self.l[pos]
                return None
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101229/cd8481c7/attachment.html>

More information about the Tutor mailing list