Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'operator': 0.04; 'attributes': 0.05; 'advance,': 0.07; 'attribute': 0.07; 'used.': 0.07; 'python': 0.08; '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; '>>>': 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; 'stack': 0.24; 'code': 0.25; 'function': 0.27; 'all,': 0.28; 'compare': 0.28; 'print': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'kelly': 0.30; 'subject:each': 0.30; 'subject:?': 0.31; 'objects': 0.32; 'header:User-Agent:1': 0.33; 'this.': 0.33; 'fri,': 0.34; 'flag': 0.34; 'frame': 0.34; 'thank': 0.35; 'thread': 0.37; 'skip:" 10': 0.37; 'received:192': 0.37; "there's": 0.37; 'using': 0.38; 'should': 0.39; 'subject:how': 0.39; 'received:192.168': 0.40; 'your': 0.61; '2012': 0.67; 'identity.': 0.67; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'address,': 0.72; 'build-in': 0.84; 'case?': 0.84 Date: Fri, 06 Jan 2012 14:56:26 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15 MIME-Version: 1.0 To: dmitrey Subject: Re: how to get id(function) for each function in stack? References: <1002d4cd-6cfe-4b79-917f-361a06ffd215@a11g2000vbz.googlegroups.com> <9f8a8fd4-3541-4f9b-a887-3d10524de8f1@t30g2000vbx.googlegroups.com> In-Reply-To: <9f8a8fd4-3541-4f9b-a887-3d10524de8f1@t30g2000vbx.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:5wBTIZNuwLKsDOV+uy6P2KsZyDp0B4OpWaPaAJZqz/c NgaJ7JYzArdW2h9s+DzzA2cJxAhCLqQ13hK844TE//rqbBRaiV zgnFjUOn2Mt9PkyFnryFIeuh7JKByfQJTy1SsZB5rmUvqYMxc4 IGEPGCxDoCQyeqtf7Wlg5II1uwUTvT6q+fqgMjlX4fsRA9CY0k r0WQgi/eLuotTKN1CRFqdMzvxNP99VlXimLrqZhaypNTftmS96 t9Rya/ldV471KxM9jl8EWIkLXDExAFcy7GCIc9Vm8+MhNd9WvH JH+C89Jz00Rv/GH3z4w0TouSZ0YNXAkjl1bb7b54aYaOmN4BC5 eF7IYkEAwZDw68CP6gL0= Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name 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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1325879798 news.xs4all.nl 6858 [2001:888:2000:d::a6]:52231 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18616 On 01/06/2012 02:29 PM, dmitrey wrote: > On Jan 6, 8:28 pm, Ian Kelly wrote: >> 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 > 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