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
- 2.1.5 Python元類深刻理解(metaclass)Python
- 元類:Metaclass
- 【python】python安裝Python
- python ----python的安裝Python
- python:python的多程式Python
- python--- 之The program 'python' can be found in the following packages: * python-minimal * python3PythonPackage
- Python IDLE和Python的區別!Python入門教程Python
- python學習之初識pythonPython
- 【Python】python類的繼承Python繼承
- Python 序列化(Python IO)Python
- Python合集之Python函式Python函式
- pythonPython
- python _Python
- python教程(一)·python環境搭建Python
- 學習Python的日子 Python(6)Python
- [python] Python型別提示總結Python型別
- Python補充02 Python小技巧Python
- 小白自學Python(一) -- Python教程Python
- Python之將Python字串生成PDFPython字串
- Python 字串格式化(Python IO)Python字串格式化
- Python 檔案讀寫(Python IO)Python
- 『python入門:』 python的介紹Python
- 與 Python 之父聊天:更快的 Python!Python
- python(python中的super函式、)Python函式
- python中#!/usr/bin/python與#!/usr/bin/env python的區別Python
- Python入門:Python 2與Python3有什麼區別?Python
- 學習Python選擇Python2還是Python3呢?Python
- Python學習筆記|Python之程式Python筆記
- Python 筆記-2-1-Python 概述Python筆記
- Python 微服務開發--Python Microservices DevelopmentPython微服務ROSdev
- python SQL基礎與python互動PythonSQL
- 「Python」Convert map object to numpy array in python 3PythonObject
- 【Python】阿里雲python sdk快速入門Python阿里
- Python - opencv-python 獲取影片尺寸PythonOpenCV
- Python基礎篇-Python基礎01Python
- Python基礎之Python資料世界Python
- 有趣的Python:Python控制鍵盤滑鼠Python
- Python是什麼?Python有哪些框架?Python框架