Python type and object relationship
2013-06-25 12:15
267 查看
1) Everything is object in Python, even types (what the hell, how can this happen ? See below bullet points)
2) "class" and "type" are the same thing, they are "type objects". "Type objects" can be subclassed. The other objects in Python are "concrete objects" which are instantiated of "type objects" (class or type) and they can't be subclassed.
3) "type" is a concrete instance of itself (what the hell).
4) "type" is metaclass which is used to create new classes/types
5) "object" is a "class" and it is a concrete instance of "type". Note, "object" doesn't inherit from "type", instead it is instantiated of "type" by the CPython runtime. CPython CORE need do special
initialization for "type" and "object", because they are interdependent (Chicken and Egg problem). This is why "isinstance(object, type) == True".
The following pseudo code should help understand how CPython CORE init these two.
# object's class is type object.__class__ = type # PyType_Ready(type) sets: type.__bases__ = (object,) type.__class__ = type(object)
相关文章推荐
- Python Type Class and Object的文章
- python报错 TypeError: object() takes no parameters
- python Class(类) and Object Oriented(面向)
- python 报错TypeError: 'range' object does not support item assignment,解决方法
- Python: TypeError: 'dict' object is not callable
- Python PIP Install throws TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
- python3.6 TypeError: 'dict_keys' object does not support indexing
- python import 错误 TypeError: 'module' object is not callable
- SQLAlchemy——Python SQL toolkit and Object Relational Mapper
- [Python][转]Exception AttributeError: "'NoneType' object has no attribute
- 【Python】TypeError: 'module' object is not callable 原因分析
- IronPython and LINQ to Objects (IV): 实现IEnumerable<Object>
- python:字符串和数字拼接 (TypeError: Can't convert 'int' object to str implicitly)
- Python_TypeError:object() takes no parameters
- python使用PIL库报错,'NoneType' object has no attribute 'bands'
- Python3问题TypeError: object() takes no parameters
- python面向对象-理清object与type的关系
- python __def__ Exception AttributeError: "'NoneType' object has no attribute
- python type(object) 与 isinstance(object, base) 区别
- 【Python】TypeError: 'module' object is not callable 原因分析