ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Metaclass in Python

Metaclass in Python

原创 Linux操作系统 作者:jieforest 时间:2012-07-06 11:07:24 0 删除 编辑
[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.

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/,如需转载,请注明出处,否则将追究法律责任。

下一篇: MOVE模式
请登录后发表评论 登录
全部评论

注册时间:2008-04-23

  • 博文量
    443
  • 访问量
    508478