How to inspect who is caller of func and who is the class of instance

1. Who is the class of self instance ?

class aa(object):
    def a(self):

        if self.__class__.__name__ == ‘aa‘:
            print "aa, a func()"
        elif self.__class__.__name__ == "bb":
            print "bb, a func()"

class bb(aa):
    def b(self):
        print "aa, b func()"

aa().a()
bb().a()

---------------------------------------------------------------------
result :
aa, a func()
bb, a func()

2.Who is the caller of function

import inspect

class aa(object):
    def a(self):
        frame = inspect.currentframe()

        print "The caller is %s" %frame.f_back.f_code.co_name

    def callerOfa(self):
        self.a()

aa().callerOfa()
aa().a()

---------------------------------------------------------------
result:
The caller is callerOfa
The caller is <module>
时间: 2024-09-07 10:20:46

How to inspect who is caller of func and who is the class of instance的相关文章

【javascript】arguments.callee、func.caller

1.arguments.callee  function test() { console.log(arguments.callee); } 打印函数自己 运用: 立即执行函数里使用递归    var num = (function() {                   if(n == 1) {                         return 1;                   }      return n * arguments.callee(n - 1);    

jquery颜色选择器

本站下载 第二种:纯JAVASCRIPT: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2311"> <title>DW调色板</title> <script> var ColorHex=new Array('00','33','66','99','CC','FF') var SpColo

递归降序遍历目录层次结构,并按文件类型计数

本程序使用了一些对目录进行操作的函数编写了一个遍历文件层次结构的程序,最后对各种类型的文件计数.这个程序只有一个参数,它说明起点路径名,从该点开始递归降序遍历文件层次结构.其中还用到了一个为路径名动态分配存储区的函数path_alloc. // ftw.c // 2015-08-18 Lucifer Zhang // Recursively descend a directory hierarchy, counting file types #include "apue.h" #inc

Discuz common.js代码注释(二)

//获取浏览器版本号 function browserVersion(types) { var other = 1; //默认版本号 for (i in types) { //遍历types var v = types[i] ? types[i] : i; if (USERAGENT.indexOf(v) != -1) { //USERAGENT:浏览器请求头的User-Agent属性 var re = new RegExp(v + '(\\/|\\s|:)([\\d\\.]+)', 'ig')

Js收藏-转

/** * <P> Title: JavaScript Util </P> * <P> Description: JavaScript 工具 </P> * <P> Modify: 2011/11/30 </P> * @author 冯万里 * @version 1.0 * * 为减少 js 关键词的占用,此文件只占用“c$”一个关键词; * 使用时用: c$.函数名(参数列表); 或者 c$().函数名(参数列表) * 字符串操作函数

用于兼容浏览器的js写法

用于引用的源文件代码: var Common = { getEvent: function() {//ie/ff if (document.all) { return window.event; } func = getEvent.caller; while (func != null) { var arg0 = func.arguments[0]; if (arg0) { if ((arg0.constructor == Event || arg0.constructor == MouseEv

JS与IE/Firefox兼容性汇总

以下以 IE 代替 Internet Explorer,以 MF 代替 Mozzila Firefox1. document.form.item 问题     (1)现有问题:         现有代码中存在许多 document.formName.item("itemName") 这样的语句,不能在 MF 下运行     (2)解决方法:         改用 document.formName.elements["elementName"]     (3)其它 

APUE学习笔记:第四章 文件和目录

4.1 引言 本章将描述文件的特征和文件的性质 4.2 stat.fstat和lstat函数 #include<sys/stat.h> int stat(const char *restrict pathname,struct stat *restrict buf); int fstat(int filedes,struct stat *buf) int lstat(const char *restrict pathname,struct stat *restrict buf); 三个函数的返

js实现点击按钮实现上一张下一张相册滚动效果

/****判断图片是否构成滚动效果*/$(function(){    if($("#bar").find('img').size()*71<=$("#bar").width()){           $("#table_img").width($("#bar").find('img').size()*71);    }    if($("#bar").find('img').size()*71&g