On 14Feb2012 13:13, Zheng Li <dllizh...@gmail.com> wrote:
| > On 13Feb2012 15:59, Zheng Li <dllizh...@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 <c...@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 <ryv...@email.sps.mot.com>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to