Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'context': 0.04; 'received:edu.au': 0.07; 'weekend,': 0.07; 'subject:method': 0.09; '"test"': 0.16; 'a()': 0.16; 'btw:': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'out?': 0.16; 'received:202.125.174': 0.16; 'received:202.125.174.133': 0.16; 'received:boardofstudies.nsw.edu.au': 0.16; 'received:cskk.homeip.net': 0.16; 'received:harvey.boardofstudies.nsw.edu.au': 0.16; 'received:homeip.net': 0.16; 'received:nsw.edu.au': 0.16; 'subject: \n ': 0.16; 'subject:instance': 0.16; 'throwaway': 0.16; 'cc:addr:python-list': 0.16; 'question.': 0.16; 'wrote:': 0.18; 'instance': 0.18; 'reason,': 0.18; 'maybe': 0.21; 'header:In- Reply-To:1': 0.22; 'static': 0.24; 'cc:2**0': 0.26; 'code': 0.26; 'figure': 0.26; 'second': 0.28; 'class': 0.29; 'problem': 0.29; 'cc:addr:python.org': 0.29; 'correct': 0.29; 'invoke': 0.30; 'outer': 0.30; 'do.': 0.31; 'sufficient': 0.32; 'rest': 0.32; 'there': 0.33; 'header:User-Agent:1': 0.33; 'it.': 0.33; 'too': 0.33; 'decide': 0.33; 'object': 0.33; 'normally': 0.34; 'wondering': 0.34; 'all.': 0.34; 'be,': 0.34; 'curious': 0.34; 'test.': 0.34; 'something': 0.35; 'received:au': 0.36; 'question': 0.36; 'but': 0.37; 'charset:us-ascii': 0.37; 'some': 0.38; 'useful': 0.38; 'subject:how': 0.39; 'application': 0.40; 'week.': 0.40; 'might': 0.40; 'simple': 0.61; 'your': 0.61; 'making': 0.64; 'received:202': 0.66; 'course.': 0.66; 'cameron': 0.77; 'often,': 0.84; 'subject:tell': 0.91; 'arise': 0.96 Date: Tue, 14 Feb 2012 20:52:23 +1100 From: Cameron Simpson To: Zheng Li Subject: Re: how to tell a method is classmethod or static method or instance method MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9150D72E-0014-4D45-A7C2-758D7BE5F3CD@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) References: <9150D72E-0014-4D45-A7C2-758D7BE5F3CD@gmail.com> Cc: python-list 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: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1329213138 news.xs4all.nl 6895 [2001:888:2000:d::a6]:56146 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:20392 On 14Feb2012 13:13, Zheng Li wrote: | > On 13Feb2012 15:59, Zheng Li wrote: | > | how to tell a method is class method or static method or instance method? | > | > Maybe a better question is: | > under what circumstances do you need to figure this out? | | I can get "method1" of class "Test" by | a = getattr(Test, "method1") | | and I also want know how to invoke it | a() or a(Test()) Normally: a(T) where T is an object of type/class Test. So your second approach is notionally correct (aside from making a throwaway object that is then discarded). | BTW: | I don't see what the problem is if I ask a question just because I am curious about it. There's nothing wrong with it at all. But often, questions arise from some other circumstances and this one is of such a flavour that if you wanted this code in a real application it would _often_ be the wrong solution to seek, because normally you know how to call something - it is not normally useful to introspect it to decide what to do. So I was wondering what the outer context might be, because there may well have been a better solution to the situation that brought up the specific question. Simple curiosity is sufficient reason, of course. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Too young to rest on the weekend, too old to rest during the week. - Mark Randol