Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20392
| Date | 2012-02-14 20:52 +1100 |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Subject | Re: how to tell a method is classmethod or static method or instance method |
| References | <9150D72E-0014-4D45-A7C2-758D7BE5F3CD@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5796.1329213138.27778.python-list@python.org> (permalink) |
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>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
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
csiph-web