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


Groups > comp.lang.python > #18613

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

References <1002d4cd-6cfe-4b79-917f-361a06ffd215@a11g2000vbz.googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-01-06 11:28 -0700
Subject Re: how to get id(function) for each function in stack?
Newsgroups comp.lang.python
Message-ID <mailman.4490.1325874536.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Jan 6, 2012 at 11:02 AM, dmitrey <dmitrey15@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

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