鱼C论坛

 找回密码
 立即注册
查看: 3702|回复: 7

类中加(object)是什么意思呢

[复制链接]
发表于 2016-11-8 20:13:55 | 显示全部楼层 |阅读模式
10鱼币
本帖最后由 箜白 于 2016-11-9 09:33 编辑

http://bbs.fishc.com/thread-48888-1-2.html

__dict__扩展对象,下面__dict__在哪里? 为什么要加(object)?

  1. class PlugIn(object):
  2.     def __init__(self):
  3.         self._exported_methods = []
  4.         
  5.     def plugin(self, owner):
  6.         for f in self._exported_methods:
  7.             owner.__dict__[f.__name__] = f

  8.     def plugout(self, owner):
  9.         for f in self._exported_methods:
  10.             del owner.__dict__[f.__name__]

  11. class AFeature(PlugIn):
  12.     def __init__(self):
  13.         super(AFeature, self).__init__()
  14.         self._exported_methods.append(self.get_a_value)

  15.     def get_a_value(self):
  16.         print( 'a feature.')

  17. class BFeature(PlugIn):
  18.     def __init__(self):
  19.         super(BFeature, self).__init__()
  20.         self._exported_methods.append(self.get_b_value)

  21.     def get_b_value(self):
  22.         print('b feature.')

  23. class Combine:pass

  24. c = Combine()
  25. AFeature().plugin(c)
  26. BFeature().plugin(c)

  27. c.get_a_value()
  28. c.get_b_value()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-11-8 20:13:56 | 显示全部楼层
http://stackoverflow.com/questions/4015417/python-class-inherits-object
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-11-9 09:00:17 | 显示全部楼层
加object是标识继承啊
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2016-11-9 09:34:44 | 显示全部楼层
三少爷 发表于 2016-11-9 09:00
加object是标识继承啊

加与不加有什么区别吗
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-11-12 20:14:45 | 显示全部楼层
是标识继承
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2016-11-14 08:24:02 | 显示全部楼层

加与不加有什么区别吗
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-11-14 12:29:04 | 显示全部楼层
表示继承对象的类,你不加就不继承,没有影响
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-11-21 21:18:43 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-23 19:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表