class CompiledClass:
def __init__(self, pattern, flags):
#setup class here
def finditer(self, s):
#perform the find or whatever it is you’re doing on the string and yield each result or return a list.
def _compile(pattern, flags):
#do any checks or setup before creating/returning the class
return CompiledClass(pattern, flags)
如果您创建了一个具有实例方法
finditer
的类,并在_compile
方法中返回它,那么您就可以使用它。这基本上就是re所做的在不知道你想做什么的情况下,我会告诉你我的意思:
相关问题 更多 >
编程相关推荐