Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python 3.1 - DictType not part of types module?

This is what I found in my install of Python 3.1 on Windows.

Where can I find other types, specifically DictType and StringTypes?

>>> print('\n'.join(dir(types)))
BuiltinFunctionType
BuiltinMethodType
CodeType
FrameType
FunctionType
GeneratorType
GetSetDescriptorType
LambdaType
MemberDescriptorType
MethodType
ModuleType
TracebackType
__builtins__
__doc__
__file__
__name__
__package__
>>> 
like image 341
hyper_w Avatar asked Sep 22 '10 17:09

hyper_w


1 Answers

According to the doc of the types module (http://docs.python.org/py3k/library/types.html),

This module defines names for some object types that are used by the standard Python interpreter, but not exposed as builtins like int or str are. ...

Typical use is for isinstance() or issubclass() checks.

Since the dictionary type can be used with dict, there is no need to introduce such a type in this module.

>>> isinstance({}, dict)
True
>>> isinstance('', str)
True
>>> isinstance({}, str)
False
>>> isinstance('', dict)
False

(The examples on int and str are outdated too.)

like image 142
kennytm Avatar answered Nov 14 '22 23:11

kennytm