2012-07-16 61 views
4

我有一个关于python 2.X和python 3.X之间区别的小问题。 为什么在Python 3类型模块是如此之小?日Thnxpython 3类型模块

Python 2.7 
>>> import types  
>>> print(len([i for i in dir(types) if not i.startswith('__')])) 
37 


Python 3.2 
>>> import types  
>>> print(len([i for i in dir(types) if not i.startswith('__')])) 
12 

回答

6

在Python 3.x中,该types模块去掉那些已经通过像内置的命名空间更容易进行访问的所有类型。例如,您将看到ListTypeIntType已被删除,因为您可以分别通过listint来简单访问它们。

+0

这是您的建议还是有关于此的官方文档? – 2012-07-16 10:58:02

+0

它在python-dev上进行了深入讨论。最初的意图是完全删除类型模块,但它被证明是不切实际的,因为没有很好的地方放置一些其他类型,如FunctionType。 这里是它原本的证据被提名为去除: http://wiki.python.org/moin/Python3.0 下面是一些Python-dev的讨论: http://mail.python.org/ pipermail/python-dev/2007-November/075384.html http://mail.python.org/pipermail/python-dev/2007-November/075456.html – ToBeReplaced 2012-07-16 11:30:28

+0

Thnx for info – 2012-07-16 12:41:18