1.http://python-china.org/t/77 有关method binding的理解

2.[Python] dir() 与 __dict__,__slots__ 的区别

3.Descriptor HowTo Guide

4.如何理解 Python 的 Descriptor?

5.简明Python魔法 - 1

6.简明Python魔法 - 2

7.详解Python中 __get__和__getattr__和__getattribute__的区别

8.定制类

9.Python 的 type 和 object 之间是怎么一种关系?

10.python MethodType方法详解和使用

下面的几段代码为什么能够正确运行,运行时都发生了些什么???

class MyInt(int):
def __init__(self, v):
pass
def square(self):
return self * self def hello():
print 'hello' n = MyInt(2)
print n.__dict__
print MyInt.__dict__
n.hello = hello
n.hello()
print n.__dict__
import types
class Log(object):
def __init__(self, f):
self.f = f
def __get__(self,obj,cls):
print self.f.__name__, 'called'
return types.MethodType(self.f, obj, cls) class C(object):
@Log
def f(self):
pass
c = C()
c.f()
class C1(object):
a = 'abc'
def __getattribute__(self, *args, **kwargs):
print("__getattribute__() is called")
return object.__getattribute__(self, *args, **kwargs) def __getattr__(self, name):
print("__getattr__ is called")
return name + "from getattr" def __get__(self, instance, owner):
print("__get__() is called", instance, owner)
return self def foo(self, x):
print(x) class C2(object):
d = C1() if __name__ == "__main__":
c = C1()
c2 = C2()
print "====="
print(c.a)
print "------"
print(c.zzzz)
print "------"
c2.d
print "------"
print(c2.d.a)

【python】类(资料+疑惑)的更多相关文章

  1. 走进 Python 类的内部

    这篇文章和大家一起聊一聊 Python 3.8 中类和对象背后的一些概念和实现原理,主要尝试解释 Python 类和对象属性的存储,函数和方法,描述器,对象内存占用的优化支持,以及继承与属性查找等相关 ...

  2. Python类属性,实例属性

    1.Python类数据属性:定义在类里面但在函数外面的变量,它们都是静态的. #一段很简单的代码,但反应了很多 >>> class A(): a=1 #一个类里面有个属性a > ...

  3. python 类继承演示范例的代码

    把做工程过程重要的代码片段备份一次,下面的资料是关于python 类继承演示范例的代码. # a simple example of a class inheritance # tested with ...

  4. python相关资料链接

    后续的博客更新,会涉及到很多的python及python的框架相关的内容,这里将自己收藏的一些关于python相关资料的链接做一个整理,算是一个导航索引吧... PS:其中有些链接对应的技术团队文章, ...

  5. python类学习以及mro--多继承属性查找机制

    版权声明:本文为博主原创文章,未经博主允许不得转载. 还记得什么是新式类和旧式类吗? Python中,一个class继承于object,或其bases class里面任意一个继承于object,这个c ...

  6. python类的书写、调用

    注意:stu1=Luffy('xing',19)   和  Luffy.__init__(stu1,'xing',19) 是等价的. 查看类的使用方法 粘贴一个网上python学习资料

  7. 第7.17节 Python类中的静态方法装饰器staticmethod 定义的静态方法深入剖析

    第7.17节  Python类中的静态方法装饰器staticmethod 定义的静态方法深入剖析 静态方法也是通过类定义的一种方法,一般将不需要访问类属性但是类需要具有的一些能力可以静态方法提供. 一 ...

  8. Python类中super()和__init__()的关系

    Python类中super()和__init__()的关系 1.单继承时super()和__init__()实现的功能是类似的 class Base(object): def __init__(sel ...

  9. LightMysql:为方便操作MySQL而封装的Python类

    原文链接:http://www.danfengcao.info/python/2015/12/26/lightweight-python-mysql-class.html mysqldb是Python ...

随机推荐

  1. ASP.NET MVC载入页面常用方法

    @RenderBody 在Razor引擎中没有了“母版页”,取而代之的是叫做“布局”的页面(_Layout.cshtml)放在了共享视图文件夹中.在这个页面中,会看到标签里有这样一条语句: @Rend ...

  2. VMware网络设置详解

    标签: 网络vmware虚拟机web服务network 2009-05-19 22:23 27537人阅读 评论(7) 收藏 举报 分类: 基于类linux的开发(171) 我们知道,VMwareWo ...

  3. centos虚拟机网络桥接配置

    1.虚拟机设置->网络适配器->选择桥接模式->重启虚拟机 2.使用命令进行配置IP地址 (引用别人的配置命令) 修改/etc/sysconfig/network-scripts 目 ...

  4. Github代理设置

    启用代理 git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080 git config --glo ...

  5. python 爬取乌云所有厂商名字,url,漏洞总数 并存入数据库

    需要:MySQLdb 下面是数据表结构: /* Navicat MySQL Data Transfer Source Server : 127.0.0.1 Source Server Version ...

  6. PHPstorm的数据库功能

    PHPstorm真是神器,居然有表.视图.存储过程的功能,非常人性化,建表那叫一个舒服,而且sql语句可以像其他代码一样显示"区域",结构更加清晰.

  7. bootstrap 水平表单

    <form class="form-horizontal" role="form"> <div class="form-group& ...

  8. WebApplicationInitializer (spring 3.x.x以上版本)

    实现WebApplicationinitializer接口的类都可以在web应用程序启动时被加载. 那么来想一个问题:为什么实现了WebApplicationInitializer这个接口后,onSt ...

  9. .net core 跨平台实践

    本人采用Ubuntu 14.04 来实现.net core 的跨平台实践. 首先安装Ubuntu14.04系统.安装细节问百度. 1..net core console程序的跨平台 首先新建一个con ...

  10. AOP基本名词解释