List<字典> 排序(coding记录)

List<字典> 排序(coding记录)

    #region 给中侧板排序
    System.Comparison<P03tatamiMiddleSidePanlCentre> comparison = new System.Comparison<P03tatamiMiddleSidePanlCentre>
         ((P03tatamiMiddleSidePanlCentre x, P03tatamiMiddleSidePanlCentre y) =>
         {
             if (x.PY < y.PY)
                 return -1;//小于
             else if (x.PY == y.PY)
                 return 0;//等于
             else
                 return 1;//大于
         });//将数据从小到大排序

    MiddlePanelLong.Sort(comparison);

    int i = 1;
    foreach (P03tatamiMiddleSidePanlCentre mspc in MiddlePanelLong)
    {
        mspc.OdinalY = i;
        i++;
    }
    #endregion
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码是一个用于编码转换的示例,它展示了如何使用Python来实现将Unicode数据编码为XML和HTML实体的功能。 让我们逐句解释一下代码: ```python import codecs from htmlentitydefs import codepoint2name ``` 首先,导入了codecs库和codepoint2name模块,后者包含了HTML实体的名称和对应的Unicode码点。 ```python def encode_for_xml(unicode_data, encoding='ascii'): return unicode_data.encode(encoding, 'xmlcharrefreplace') ``` 这是一个名为encode_for_xml的函数,它接受一个Unicode字符串和一个可选的编码参数。它使用给定的编码对Unicode数据进行编码,并将无法编码的字符替换为XML字符引用。 ```python def html_replace(exc): if isinstance(exc, (UnicodeEncodeError, UnicodeTranslateError)): s = [u'&%s;' % codepoint2name[ord(c)] for c in exc.object[exc.start:exc.end]] return ''.join(s), exc.end else: raise TypeError("can't handle %s" % exc.__name__) codecs.register_error('html_replace', html_replace) ``` 这是一个名为html_replace的函数,它是一个错误处理函数。当遇到无法编码的字符时,将调用此函数来处理。它将无法编码的字符替换为对应的HTML实体。 ```python def encode_for_html(unicode_data, encoding='ascii'): return unicode_data.encode(encoding, 'html_replace') ``` 这是另一个编码函数,名为encode_for_html。它与encode_for_xml函数类似,但是使用html_replace函数来处理无法编码的字符。 ```python if __name__ == '__main__': unicode_data = u'\N{LATIN SMALL LETTER A WITH DIAERESIS}' print encode_for_xml(unicode_data, encoding='ascii') data = u''' <html> <head> <title>Encoding Test</title> </head> <body> <p>accented characters: <ur> <li>\xe0 (a + grave) <li>\xe7 (c + cedilla) <li>\xe9 (a + acute) </ul> <p>symbols: <ul> <li>\xa3 (British pound) <li>\u20ac (Euro) <li>\u221e (infinity) </ul> </body></html> ''' print encode_for_xml(data) print encode_for_html(data) ``` 在这个if __name__ == '__main__'的块中,我们定义了一些测试数据并调用了encode_for_xml和encode_for_html函数来进行编码转换。输出将会显示Unicode数据的编码结果。 至于html_replace(exc)函数的参数例子,你可以将其添加到代码中并进行测试。例如: ```python def html_replace(exc): if isinstance(exc, (UnicodeEncodeError, UnicodeTranslateError)): s = [u'&%s;' % codepoint2name[ord(c)] for c in exc.object[exc.start:exc.end]] return ''.join(s), exc.end elif isinstance(exc, UnicodeDecodeError): # 示例参数例子 return u'&%s;' % codepoint2name[ord(exc.object[exc.start])], exc.end else: raise TypeError("can't handle %s" % exc.__name__) ``` 这样,当遇到Unicode解码错误时,将替换为对应的HTML实体。你可以在测试数据中添加一些无法解码的字符来进行测试。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值