TableOfContents

Include(ZPyUGnav)

设计模式vsPythonic~数据转换

编码对应式~黄毅

黄毅 <[email protected]>
reply-to        [email protected]
to      [email protected]
date    Thu, Sep 18, 2008 at 00:25
subject [CPyUG:65953] Re: 关于“设计模式”的一个问题

考虑 字符串 和 unicode 之间的这种关系

   1 def encode_fmt1(midi_fmt_data):
   2     return fmt1_data
   3  
   4 def decode_fmt1(fmt1_data):
   5     return midi_fmt_data
   6  
   7 #...
   8  
   9 encoders = {
  10     fmt1: encode_fmt1,
  11     #...
  12 }
  13  
  14 decoders = {
  15     fmt1: decode_fmt1,
  16     #...
  17 }
  18  
  19 def transform(data, fmt_from, fmt_to):
  20      encoder = encoders[fmt_from]
  21      decoder = decoders[fmt_to]
  22      return encoder(decoder(data))


反馈

创建 by -- ZoomQuiet [DateTime(2008-09-17T23:40:17Z)]

PageComment2

[:/PageCommentData:PageCommentData]