__new__

  object.__new__(cls[, ...])

  Called to create a new instance of class cls. 用于创建类对象cls的实例。

  __new__() is a static method (special-cased so you need not declare it as such) __new__是一个特殊的方法,不需要声明为static方法。第一个参数是类对象。其余的参数会被传递给__init__。

  If __new__() returns an instance of cls, then the new instance’s __init__() method will be invoked like __init__(self[, ...]), where self is the new instance and the remaining arguments are the same as were passed to __new__().

  If __new__() does not return an instance of cls, then the new instance’s __init__() method will not be invoked.

  __new__() is intended mainly to allow subclasses of immutable types (like int, str, or tuple) to customize instance creation. It is also commonly overridden in custom metaclasses in order to customize class creation.

__new__的更多相关文章

  1. __new__静态方法

    __new__静态方法 新式类都有一个__new__的静态方法,它的原型是object.__new__(cls[, ...]) cls是一个类对象,当你调用C(*args, **kargs)来创建一个 ...

  2. __new__方法

    __new__:创建对象时调用,返回当前对象的一个实例__init__:创建完对象后调用,对当前对象的实例的一些初始化,无返回值 案例一: >>> class A(object): ...

  3. Python中的__new__和__init__

    Python中的__new__和__init__ 写了这么多的class,现在才知道还有个__new__方法, 那么它和__init__有什么区别呢? class TestCls(): "& ...

  4. Python中的__init__和__new__介绍

    介绍 首先我们要知道在面向对象编程中,实例化基本遵循创建实例对象.初始化实例对象.最后返回实例对象这么一个过程. Python 中的 __new__ 方法负责创建一个实例对象,__init__ 方法负 ...

  5. [深入Python]__new__和__init__

    class A(object): def __init__(self): print "init" def __new__(cls,*args, **kwargs): print ...

  6. __new__ 的简单应用

    用__new__与__init__不同,通过继承内建类型对象,__new__可以用来创建一个简单的新类型,在__new__加入一些动作以完成创建. class RoundFloat(float): d ...

  7. python中的__init__ 、__new__、__call__小结

    这篇文章主要介绍了python中的__init__ .__new__.__call__小结,需要的朋友可以参考下 1.__new__(cls, *args, **kwargs)  创建对象时调用,返回 ...

  8. [Python] Python 之 __new__() 方法与实例化

    __new__() 是在新式类中新出现的方法,它作用在构造方法建造实例之前,可以这么理解,在 Python 中存在于类里面的构造方法 __init__() 负责将类的实例化,而在 __init__() ...

  9. Python中的__new__()方法的使用

    __new__() 函数只能用于从object继承的新式类. 先看下object类中对__new__()方法的定义: class object:   @staticmethod # known cas ...

随机推荐

  1. HTML5播放器

    seweise palyer http://www.whatled.com/m/?post=1626 https://github.com/sewise/sewise-player2 七牛云音视频支持 ...

  2. Morphia 学习一 注解

    http://blog.csdn.net/liumm0000/article/details/7535858 生命周期方法注解(delete没有生命周期事件)@PrePersist save之前被调用 ...

  3. knockout 学习实例3 html

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  4. 在Ext JS 6中添加本地化包

    我在官方论坛发的帖子终于有人恢复了,也终于知道如何添加本地化包了.在Ext JS 6中,Ext JS属于经典工具包,而本地化是包含在经典工具包中,因而在app.json中,要添加本地化包,必须在cla ...

  5. ios实现屏幕旋转的方法

    1.屏蔽AppDelegate下面的屏幕旋转方法 #pragma mark - 屏幕旋转的 //- (UIInterfaceOrientationMask)application:(UIApplica ...

  6. struts2&&Hibernate Demo1

    这篇文章和<struts1&&Hibernate Demo1>基本类似,我这里只是拷贝代码了. 最核心的代码:LoginAction.java package action ...

  7. decimal,float和double的区别

    http://www.cnblogs.com/yellowapplemylove/archive/2011/08/23/2150316.html 一直很奇怪C#的预定义数据类型中为什么加了一个deci ...

  8. Java Socket网络编程的经典例子(转)

    事实上网络编程简单的理解就是两台计算机相互通讯数据而已,对于程序员而言,去掌握一种编程接口并使用一种编程模型相对就会显得简单的多了,Java SDK提供一些相对简单的Api来完成这些工作.Socket ...

  9. http://www.iis.net/downloads/microsoft/url-rewrite

    http://www.iis.net/downloads/microsoft/url-rewrite iis  url重写模块.官方下载

  10. EF 示例

    EF有三种数据库访问方式,这里只介绍Code First. 1.DB First,类似Linq to sql中拖拽一个DB到方案中 2.Model First,没试过,不能自动生成数据库只能生成表 3 ...