def IME(self) : #it is total function
output = ""
print "Exit by ctrl + D"
while 1 :
character = raw_input("")
if character in self.alphabet :
result = self.transition(character) # get result [next state, output character] from constructed by automata
output = output + str(result[1])
print output
self.currentState = result[0]
else :
output = output + character
print output
self.currentState = 0
我用python制作了一个IME(输入法编辑器)模拟器。它就像有限状态机,当输入来并输出在 python 程序上显示结果时。不知道结果如何一一显示,所以想请教一下如何像命令行样式一样显示。
问题是两件事,
- 如何一一表达每个结果?
- 如何实现“空格”或“退格”?
输入“del(退格)键”时可以使用此代码吗?
elif character == '\033' output = output[0:len(output)-1]