Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18616

Re: how to get id(function) for each function in stack?

Date 2012-01-06 14:56 -0500
From Dave Angel <d@davea.name>
Subject Re: how to get id(function) for each function in stack?
References <1002d4cd-6cfe-4b79-917f-361a06ffd215@a11g2000vbz.googlegroups.com> <mailman.4490.1325874536.27778.python-list@python.org> <9f8a8fd4-3541-4f9b-a887-3d10524de8f1@t30g2000vbx.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.4492.1325879798.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 01/06/2012 02:29 PM, dmitrey wrote:
> On Jan 6, 8:28 pm, Ian Kelly<ian.g.ke...@gmail.com>  wrote:
>> On Fri, Jan 6, 2012 at 11:02 AM, dmitrey<dmitre...@gmail.com>  wrote:
>>> hi all,
>>> how to get id(func) for each func in stack? (I mean memory address, to
>>> compare it with id(some known funcs))
>>> Thank you in advance, D.
>> The answer hasn't changed since your last thread about this.  The
>> stack contains code objects, not functions.  You can get the code
>> objects using inspect.stack(), and compare them to the func_code
>> attributes of the functions you're interested in.
>>
>> Also, there's no need to use id() for this.  Just use the "is"
>> operator to check identity.
>>
>> for frame_tuple in inspect.stack():
>>      frame = frame_tuple[0]
>>      if frame.f_code is some_function.func_code:
>>          print("Found it!")
>>
>> Cheers,
>> Ian
> Python build-in function sum() has no attribute func_code, what should
> I do in the case?
> D.
flag = False

for frame_tuple in inspect.stack():
     frame = frame_tuple[0]
     if frame.f_code is some_function.func_code:
         flag = True

if !flag:
     print "FuncDesigner.sum() not used.  Change."






-- 

DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how to get id(function) for each function in stack? dmitrey <dmitrey15@gmail.com> - 2012-01-06 10:02 -0800
  Re: how to get id(function) for each function in stack? Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-06 11:28 -0700
    Re: how to get id(function) for each function in stack? dmitrey <dmitrey15@gmail.com> - 2012-01-06 11:29 -0800
      Re: how to get id(function) for each function in stack? Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-06 12:50 -0700
      Re: how to get id(function) for each function in stack? Dave Angel <d@davea.name> - 2012-01-06 14:56 -0500
      Re: how to get id(function) for each function in stack? Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-06 13:37 -0700
      Re: how to get id(function) for each function in stack? Lie Ryan <lie.1296@gmail.com> - 2012-01-07 11:17 +1100
      Re: how to get id(function) for each function in stack? Robert Kern <robert.kern@gmail.com> - 2012-01-07 10:39 +0000
  Re: how to get id(function) for each function in stack? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-07 00:54 +0000

csiph-web