加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Django python2和python3的区别

发布时间:2020-12-15 17:13:05 所属栏目:大数据 来源:网络整理
导读:查看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.maxsizeelse:????string_types?=?basestring,??

查看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区别还是挺明显


(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读