美文网首页
python2与python3 decode用法完全不同

python2与python3 decode用法完全不同

作者: sexy_cyber | 来源:发表于2018-06-23 18:44 被阅读16次

    这是Python2:

    Python 2.7.10 (default, Oct  6 2017, 22:29:07) 
    [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> name = 'long'
    >>> name = '龙'
    >>> name.decode('utf-8')
    u'\u9f99'
    >>> 
    
    
    

    这是python3:

    Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 03:03:55) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import urllib
    >>> name = '龙'
    >>> name.decode('utf-8')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'str' object has no attribute 'decode'
    >>> 
    
    
    

    用惯了python3的我竟然不知所措;

    相关文章

      网友评论

          本文标题:python2与python3 decode用法完全不同

          本文链接:https://www.haomeiwen.com/subject/llddyftx.html