Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75662
| Path | csiph.com!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Marko Rauhamaa <marko@pacujo.net> |
| Newsgroups | comp.lang.python |
| Subject | Re: how to call back a method in python3? |
| Date | Mon, 04 Aug 2014 08:47:31 +0300 |
| Organization | A noiseless patient Spider |
| Lines | 32 |
| Message-ID | <87y4v4kdqk.fsf@elektro.pacujo.net> (permalink) |
| References | <mailman.12616.1407121329.18130.python-list@python.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Info | mx05.eternal-september.org; posting-host="ff5cf27ef3d5b31f034d3b72bdc27a41"; logging-data="5907"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18rpE22FdfBnyNAghDQxoEg" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) |
| Cancel-Lock | sha1:TFpLFnWCYfgs2szIMEV23rcGrF4= sha1:9RDpdtn8T+QeWALLHis7AzG9iFU= |
| Xref | csiph.com comp.lang.python:75662 |
Show key headers only | View raw
"水静流深" <1248283536@qq.com>:
> I want to call back a function which is the method of a class .
>
> def callback(self.do,x):
> return(self.do(x))
>
> That is what i want to write,when i input
>
> def callback(self.do,x):
>
> error message:
Do this:
class MyClass:
def my_method(self):
def callback(x):
return self.do(x)
return callback
def do(self, x):
print("done: {}".format(x))
then call:
m = MyClass()
callback = m.my_method()
callback(7)
Marko
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how to call back a method in python3? "水静流深" <1248283536@qq.com> - 2014-08-04 09:56 +0800
Re: how to call back a method in python3? Marko Rauhamaa <marko@pacujo.net> - 2014-08-04 08:47 +0300
Re: how to call back a method in python3? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-08-04 18:18 +1200
csiph-web