zoukankan      html  css  js  c++  java
  • Win7下 Python中文正则的奇异表现

    首先贴Win32下的直接Python shell下的测试结果:

    Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32  
    Type "copyright", "credits" or "license()" for more information.  
    >>> import re  
    >>> print re.match(ur'[u4e00-u9fa5]+',u"中国")  
    None  
    >>>   
    >>> import sys  
    >>> sys.getdefaultencoding()  
    'ascii' 
    >>> str1=u"中国"  
    >>> str1  
    u'xd6xd0xb9xfa'  

    接着来先cmd,再python命令进入python交互环境下的结果:

    Microsoft Windows [版本 6.1.7601]  
    版权所有 (c) 2009 Microsoft Corporation。保留所有权利。  
      
    C:Usersuser>python  
    Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32  
    Type "help", "copyright", "credits" or "license" for more information.  
    >>> import re  
    >>> print re.match(ur'[u4e00-u9fa5]+',u"中国")  
    <_sre.SRE_Match object at 0x00522C28>  
    >>> import sys  
    >>> sys.getdefaultencoding()  
    'ascii'  
    >>> str1=u"中国"  
    >>> str1  
    u'u4e2du56fd'  

    生产应用中的问题好像是因为codeing设置的添加而解决,和上面这个问题有一定关系,以上形式是交互环境下测试所得的结果。

    参考资料:http://www.limijd.me/2013/02/python%E9%87%8Cunicode%E5%92%8Cutf-8%E7%9A%84%E5%8C%BA%E5%88%AB/

  • 相关阅读:
    「CF505E」 Mr. Kitayuta vs. Bamboos
    「CF1438D」 Powerful Ksenia
    Kruskal重构树
    20210528模拟赛总结
    20210527模拟赛总结
    20210526模拟赛总结
    20210525模拟赛总结
    CF #722 Div2题解
    洛谷P3652 csh和zzy的战争 题解
    [清华集训2012]模积和 题解
  • 原文地址:https://www.cnblogs.com/dhcn/p/7106487.html
Copyright © 2011-2022 走看看