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: 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 Date: Fri, 6 Jan 2012 11:28:21 -0700 Subject: Re: how to get id(function) for each function in stack? To: dmitrey 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Fri, Jan 6, 2012 at 11:02 AM, dmitrey 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