Metaclass in Python
[i=s] 本帖最後由 jieforest 於 2012-7-6 11:05 編輯
In this post we will be talking about Metaclass in python. If you are reading some code which uses metaclass, you will probably come across __new__. If you are not familiar with what __new__ does, i suggest you first read about __new__.
You can read about __new__ in our last to last post.
Throughout this post we will be talking about new style. classes. Things might differ in old-style. classes.
As we go, i will be trying everything on IPython and suggest you as well to try everything on IPython.
Let's see a little bit about normal Objects in Python.
... pass
...We created a class named A. A extends from class object (Here by object we mean class named object from which all new style. classes extend).
Hereafter if we use lowercase 'o' in object, it means we want to refer to the class named object. If we use an Object with uppercase 'O', we mean an instance of some class i.e an instance created by calling the class.
Let's create an instance of A.
In this post we will be talking about Metaclass in python. If you are reading some code which uses metaclass, you will probably come across __new__. If you are not familiar with what __new__ does, i suggest you first read about __new__.
You can read about __new__ in our last to last post.
Throughout this post we will be talking about new style. classes. Things might differ in old-style. classes.
As we go, i will be trying everything on IPython and suggest you as well to try everything on IPython.
Let's see a little bit about normal Objects in Python.
CODE:
>>> class A(object):... pass
...We created a class named A. A extends from class object (Here by object we mean class named object from which all new style. classes extend).
Hereafter if we use lowercase 'o' in object, it means we want to refer to the class named object. If we use an Object with uppercase 'O', we mean an instance of some class i.e an instance created by calling the class.
Let's create an instance of A.
CODE:
>>> bj=A()來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-734765/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Python Metaclass 初探Python
- Python的metaclassPython
- Python: 陌生的 metaclassPython
- Python MetaClass深入分析Python
- python的metaclass淺析Python
- python中的元類MetaclassPython
- python當中__metaclass__探討Python
- 2.1.5 Python元類深刻理解(metaclass)Python
- 深刻理解Python中的元類(metaclass)Python
- 元類:Metaclass
- python 類和元類(metaclass)的理解和簡單運用Python
- Python之美[從菜鳥到高手]--深刻理解原類(metaclass)Python
- 【python】python安裝Python
- 【Python】Python使用redisPythonRedis
- Python 之父談 PythonPython
- 【Python】python練習Python
- 【Python】python 日期操作Python
- python ----python的安裝Python
- python:python的多程式Python
- 【Python】Python連線mysqlPythonMySql
- Python 3 能振興 PythonPython
- 【Python】Python安裝模組Python
- 【python】python APScheduler 框架Python框架
- python學習之初識pythonPython
- Python 序列化(Python IO)Python
- Python合集之Python函式Python函式
- 【Python】python類的繼承Python繼承
- 小白自學Python(一) -- Python教程Python
- 為Python加速 - python+memcachedPython
- Python 3 正在毀滅 PythonPython
- Python補充06 Python之道Python
- [python]python錯誤集錦Python
- Python list of class attributes - PythonPython
- 【python】Python 3 的新特性Python
- python--- 之The program 'python' can be found in the following packages: * python-minimal * python3PythonPackage
- python _Python
- PythonPython
- Python IDLE和Python的區別!Python入門教程Python