我在python2.x以下代码:记号化在python3.x
class _CHAIN(object):
def __init__(self, execution_context=None):
self.execution_context = execution_context
def eat(self, toktype, tokval, rowcol, line, logical_line):
#some code and error checking
operations = _CHAIN(execution_context)
tokenize(StringIO(somevalue).readline, operations.eat)
现在的问题是,在python3.x第二个参数不存在。我需要在tokenize之前调用函数operations.eat()。我们如何在python3.x中执行上述任务。一个想法是在'tokenize'语句(代码的最后一行)之前直接调用tokenize.eat()函数。但我不确定要通过的论据。我确定必须有更好的方法来做到这一点。
tokenize需要一个可调用的返回字节,而不是字符串(我也犯了这个错误) – 2011-02-10 01:00:42