微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Django python2和python3的区别

查看django源码six.py,发现Django在python2和python3的区别:

if PY3:
    string_types = str,    integer_types = int,    class_types = type,    text_type = str
    binary_type = bytes

    MAXSIZE = sys.maxsize
else:
    string_types = basestring,    integer_types = (int, long)
    class_types = (type, types.Classtype)
    text_type = unicode
    binary_type = str
    
    # 判断是不是Jython
    if sys.platform.startswith("java"):
        # Jython always uses 32 bits.
        MAXSIZE = int((1 << 31) - 1)
    else:
        # It's possible to have sizeof(long) != sizeof(Py_ssize_t).
        class X(object):

            def __len__(self):
                return 1 << 31
        try:
            len(X())
        except OverflowError:
            # 32-bit
            MAXSIZE = int((1 << 31) - 1)
        else:
            # 64-bit
            MAXSIZE = int((1 << 63) - 1)
        del X

代码可以看出Django在py2和py3区别还是挺明显


版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐