python super用法
普通继承
class FooParent(object):
def __init__(self):
self.parent = 'I\'m the parent.'
print 'Parent'
def bar(self, message):
print message, 'from Parent'
class FooChild(FooParent):
def __init__(self):
FooParent.__init__(self)
print 'Child'
def bar(self, message):
FooParent.bar(self, message)
print 'Child bar function.'
print self.parent
if __name__ == '__main__':
foochild = FooChild()
foochild.bar('Hello World!')
# output
Parent
Child
Hello World! from Parent
Child bar function.
I'm the parent.
super继承
class FooParent(object):
def __init__(self):
self.parent = 'I\'m the parent.'
print 'Parent'
def bar(self, message):
print message, 'from Parent'
class FooChild(FooParent):
def __init__(self):
super(FooChild, self).__init__()
print 'Child'
def bar(self, message):
super(FooChild, self).bar(message)
print 'Child bar function.'
print self.parent
if __name__ == '__main__':
foochild = FooChild()
foochild.bar('Hello World!')
# output
Parent
Child
Hello World! from Parent
Child bar function.
I'm the parent.
python super用法的更多相关文章
- [python] super() 用法
问题的发现与提出 在Python类的方法(method)中,要调用父类的某个方法,在Python 2.2以前,通常的写法如下: class A: def __init__(self): print & ...
- Python中的super()用法
Python中对象方法的定义很怪异,第一个参数一般都命名为self(相当于其它语言的this,比如:C#),用于传递对象本身,而在调用的时候则不 必显式传递,系统会自动传递. 今天我们介绍的主角是su ...
- python super()函数
super()函数是用来调用父类(超类)的一个方法 super()的语法: python 2 的用法: super(Class, self).xxx # class是子类的名称 class A(ob ...
- Python ---- super()使用
Python ---- super() 我们经常在类的继承当中使用super(), 来调用父类中的方法.例如下面: 1 2 3 4 5 6 7 8 9 10 11 12 13 class A: ...
- Python高级用法总结
Python很棒,它有很多高级用法值得细细思索,学习使用.本文将根据日常使用,总结介绍Python的一组高级特性,包括:列表推导式.迭代器和生成器.装饰器. 列表推导(list comprehensi ...
- python argparse用法总结
转:python argparse用法总结 1. argparse介绍 argparse是python的一个命令行解析包,非常适合用来编写可读性非常好的程序. 2. 基本用法 prog.py是我在li ...
- Anaconda下载及安装及查看安装的Python库用法
Anaconda下载及安装及查看安装的Python库用法 Anaconda 是一个用于科学计算的 Python 发行版,提供了包管理与环境管理的功能.Anaconda 利用 conda 来进行 pac ...
- python enumerate用法总结【转】
enumerate()说明 enumerate()是python的内置函数 enumerate在字典上是枚举.列举的意思 对于一个可迭代的(iterable)/可遍历的对象(如列表.字符串),enum ...
- this和super用法
1. this能分清混淆,形参名与当前对象的某个成员有相同的名字,需要明确使用this关键字来指明你要使用某个成员,使用方法是“this.成员名”. 一般以this.形参数名=形参名,代表送进来赋值的 ...
随机推荐
- Entity Framework Code-First(10.3):Property Mappings
Property Mappings using Fluent API: Here, we will learn how to configure properties of an entity cla ...
- hdu1069
#include <iostream> #include <algorithm> #include <cstring> using namespace std; c ...
- ubuntu14编译SSF(ethzasl_sensor_fusion )
参考:http://wiki.ros.org/ethzasl_sensor_fusion 1. cd catkin_ws/src/ 2 git clone git://github.com/ethz- ...
- UITableViewCell 的复用机制
cell重用机制 http://blog.cnrainbird.com/index.php/2012/03/20/guan_yu_uitableview_de_cell_fu_yong_tan_tan ...
- MongoDB自定义存储数据库文件位置
mongodb下载地址:https://www.mongodb.com/download-center#community 本机安装目录如下: 配置步骤如下: 1.新建文件夹data(文件夹内再建一个 ...
- CacheManager 概述
1. CacheManager 管理缓存,而缓存可以是基于内存的缓存,也可以是基于磁盘的缓存 2. CacheManager 需要通过 BlockMananger 来操作数据: 3. 当 Task 运 ...
- 消耗战——dp+虚树
题目 [题目描述] 在一场战争中,战场由 $n$ 个岛屿和 $n-1$ 个桥梁组成,保证每两个岛屿间有且仅有一条路径可达.现在,我军已经侦查到敌军的总部在编号为 $1$ 的岛屿,而且他们已经没有足够多 ...
- thinkphp5.1控制器初始化函数initialize与构造函数__construct区别
构造函数中子类的构造方法会覆盖父类的构造方法,如果要继承父类的构造方法可以加入parent::__construct(); 例子: //另一种方法,使用构造函数初始化 public function ...
- iOS无线真机调试
打开xcode,选择Window > Devices and Simulators 用数据线连接设备 选择 Connect via network
- jmeter 签名MD5生成(转)
请求接口需要同时发送签名,签名定义为: 可以看出签名就是把用户的密码 .用户名 和签名key生成一个md5串就可以了 刚好jmeter 有个md5 生成,生成前需要获取name ,password k ...