Differences between revisions 1 and 2
Revision 1 as of 2004-12-22 10:36:35
Size: 477
Editor: ZoomQuiet
Comment:
Revision 2 as of 2009-12-25 07:14:40
Size: 477
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
-- ZoomQuiet [[[DateTime(2004-12-22T10:36:35Z)]]]
[[TableOfContents]]
-- ZoomQuiet [<<DateTime(2004-12-22T10:36:35Z)>>]
<<TableOfContents>>

-- ZoomQuiet [2004-12-22 10:36:35]

在函数中确定其调用者 !

  • AlbertLee

  • import traceback
    
    def fun():
          s =  traceback.extract_stack()
          print '%s Invoked me!'%s[-2][2]

这个 fun 函数就可以知道是谁调用了它,并打印出来, 我们来试一下:

>>> def a():fun()

>>> def b():fun()

>>> a()
a Invoked me!
>>> b()
b Invoked me!
>>> 

PyTips/PyCallParent (last edited 2009-12-25 07:14:40 by localhost)