# -*- coding: utf-8 -*-
"""
Created on Thu Mar 29 19:26:13 2018
@author: mz
"""
class Context(object):
def SetContect(self, rhs):
self.context = rhs
def GetContext(self):
return self.context
class Interpretor(object):
def Interprets(self, context):
pass
class IntegerInterpretor(Interpretor):
def Interprets(self, context):
for c in context.GetContext():
if c.isdigit():
print("i")
else:
print("-")
class StringInterpretor(Interpretor):
def Interprets(self, context):
for c in context.GetContext():
if c.isalpha():
print("s")
else:
print("-")
if "__main__" == __na
Python 解析器模式
最新推荐文章于 2021-01-14 09:45:46 发布