Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20392 > unrolled thread

Re: how to tell a method is classmethod or static method or instance method

Started byCameron Simpson <cs@zip.com.au>
First post2012-02-14 20:52 +1100
Last post2012-02-14 20:52 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: how to tell a method is classmethod or static method or instance method Cameron Simpson <cs@zip.com.au> - 2012-02-14 20:52 +1100

#20392 — Re: how to tell a method is classmethod or static method or instance method

FromCameron Simpson <cs@zip.com.au>
Date2012-02-14 20:52 +1100
SubjectRe: how to tell a method is classmethod or static method or instance method
Message-ID<mailman.5796.1329213138.27778.python-list@python.org>
On 14Feb2012 13:13, Zheng Li <dllizheng@gmail.com> wrote:
| > On 13Feb2012 15:59, Zheng Li <dllizheng@gmail.com> 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 <cs@zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Too young to rest on the weekend, too old to rest during the week.
        - Mark Randol <ryvw50@email.sps.mot.com>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web