我有以下定义,ITEM 来自菜单。我在编码十六进制时遇到问题,因为命令的格式不同,即 var 然后是命令。请问如何让bottomtext.insert(INSERT, var + process) 执行?目前所发生的只是 testingtext.encode("hex") 被插入到底部文本中。我确实看过 exec 但似乎普遍认为 exec 没有必要?Base64 + url 编码工作正常。请问有什么帮助吗?
谢谢
def gui(item):
def default_encode(s):
s.encode('oops')
print s.encode
encodehexstring = '.encode("hex")'
mapping = {"encode_b64": base64.encodestring,"encode_url": urllib.quote_plus,"encode_hex": encodehexstring}
process = mapping.get(item, default_encode)
def getText():
#clear right text field
bottomtext.delete(1.0, END)
#var equals whats in left
var = middletext.get(1.0, 'end-1c')
#encode it
#insert encoded var in right
if process == encodehexstring:
bottomtext.insert(INSERT, var + process)
else:
bottomtext.insert(INSERT, process(var))