Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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.068 X-Spam-Evidence: '*H*': 0.86; '*S*': 0.00; 'wednesday,': 0.07; 'cc:addr:python-list': 0.15; 'foo(object):': 0.16; 'func': 0.16; 'luna': 0.16; 'subject:object': 0.16; 'utc,': 0.16; 'def': 0.20; 'wrote:': 0.21; 'method.': 0.22; 'header:In-Reply-To:1': 0.22; 'header:User-Agent:1': 0.23; 'possibly': 0.23; 'import': 0.24; 'cc:no real name:2**0': 0.26; 'subject:How': 0.27; 'cc:addr:python.org': 0.27; 'pass': 0.28; 'foo': 0.29; 'subject:skip:i 10': 0.29; 'class': 0.29; 'cc:2**0': 0.31; 'thanks': 0.34; 'subject:?': 0.34; 'should': 0.35; 'something': 0.38; 'type': 0.62; 'better': 0.63; 'header:Received:2': 0.63; 'alternative': 0.65; 'here': 0.66; 'march': 0.67; '2012': 0.69; 'bound': 0.72; 'received:194': 0.72; 'inspect': 0.91 X-IronPort-AV: E=Sophos;i="4.75,319,1330902000"; d="scan'208";a="275063" X-Virus-Scanned: amavisd-new at zimbra.sequans.com Date: Mon, 26 Mar 2012 11:44:01 +0200 From: Jean-Michel Pichavant User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) MIME-Version: 1.0 To: Jon Clements Subject: Re: How to decide if a object is instancemethod? References: <8815977.3878.1331731738209.JavaMail.geo-discussion-forums@vbux23> <389400.5582.1331733455084.JavaMail.geo-discussion-forums@vbiz13> In-Reply-To: <389400.5582.1331733455084.JavaMail.geo-discussion-forums@vbiz13> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332755057 news.xs4all.nl 6940 [2001:888:2000:d::a6]:49537 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22168 Jon Clements wrote: > On Wednesday, 14 March 2012 13:28:58 UTC, Cosmia Luna wrote: > >> class Foo(object): >> def bar(self): >> return 'Something' >> >> func = Foo().bar >> >> if type(func) == : # This should be always true >> pass # do something here >> >> What should type at ? >> >> Thanks >> Cosmia >> > > import inspect > if inspect.ismethod(foo): > # ... > > Will return True if foo is a bound method. > > hth > > Jon > another alternative : import types if type(func) == types.MethodType: pass or possibly better if isinstance(func, types.MethodType): pass JM