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?

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'operator': 0.04; 'attributes': 0.05; 'advance,': 0.07; 'func': 0.09; 'am,': 0.12; "hasn't": 0.13; '"is"': 0.16; 'subject:function': 0.16; 'cc:addr :python-list': 0.16; 'wrote:': 0.18; 'jan': 0.19; 'cc:no real name:2**0': 0.20; 'cheers,': 0.20; 'memory': 0.21; 'header:In- Reply-To:1': 0.22; 'changed': 0.23; 'objects,': 0.23; 'cc:2**0': 0.24; 'received:74.125.82.174': 0.24; 'stack': 0.24; 'code': 0.25; 'all,': 0.28; 'compare': 0.28; 'message-id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.29; 'subject:each': 0.30; 'subject:?': 0.31; 'objects': 0.32; 'this.': 0.33; 'fri,': 0.34; 'frame': 0.34; 'received:74.125.82': 0.35; 'thank': 0.35; 'thread': 0.37; 'received:74.125': 0.37; 'received:google.com': 0.37; "there's": 0.37; 'using': 0.38; 'subject:how': 0.39; 'your': 0.61; '2012': 0.67; 'identity.': 0.67; 'address,': 0.72
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=aGSIyw50bm6Zqio8u+GbEFUCxLmSN9UaYrRgbhziri0=; b=CBYfDhrJj/cOrrmu7bmbxz17KusadFgN1a0/uab8y7limTaDBTPeAOMhP5uyjMSZzY ZiMPClmPzph5U2N6uYL6uNIYdhZ9ek9AxGNMWNPbb+d2ZwJSWDzR70h0KQarz9rc+ogV 9/dPuPgYU+UQDqAjCJb4NdKmuOpWEFfhVEScs=
MIME-Version 1.0
In-Reply-To <1002d4cd-6cfe-4b79-917f-361a06ffd215@a11g2000vbz.googlegroups.com>
References <1002d4cd-6cfe-4b79-917f-361a06ffd215@a11g2000vbz.googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Fri, 6 Jan 2012 11:28:21 -0700
Subject Re: how to get id(function) for each function in stack?
To dmitrey <dmitrey15@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4490.1325874536.27778.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1325874537 news.xs4all.nl 6920 [2001:888:2000:d::a6]:33419
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:18613

Show key headers only | 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