Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104099
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Can I find the class of a method in a decorator. |
| Date | Sun, 6 Mar 2016 02:18:38 +1100 |
| Lines | 35 |
| Message-ID | <mailman.227.1457191126.20602.python-list@python.org> (permalink) |
| References | <56DAF5A7.9080503@rece.vub.ac.be> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de mHPLi6cBNDycbQY+rWMBewsfRROHn0ivus+I2ddTUq6w== |
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.010 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'run,': 0.07; 'cc:addr :python-list': 0.09; 'extern': 0.09; 'subject:method': 0.09; 'python': 0.10; 'def': 0.13; 'argument': 0.15; '...)': 0.16; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:class': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'work,': 0.21; 'decorator': 0.22; 'suppose': 0.22; 'trying': 0.22; 'am,': 0.23; 'header:In-Reply- To:1': 0.24; "doesn't": 0.26; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'idea?': 0.29; 'work.': 0.30; 'class.': 0.30; 'candidate': 0.31; 'anybody': 0.32; 'class': 0.33; 'problem': 0.33; 'received:google.com': 0.35; 'could': 0.35; "isn't": 0.35; 'there': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'subject:the': 0.39; "didn't": 0.39; 'called': 0.40; 'your': 0.60; 'mar': 0.65; 'obvious': 0.76; 'chrisa': 0.84; 'pardon': 0.84; 'to:none': 0.91; 'subject:find': 0.91; 'try.': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=SZQyTe94IeYRNaQ/OjDzBjz8HKY/xj+NSpzFSzeS/Cs=; b=qVQeLHUsrhNjlVmmGUGFemqs+C9jIwFDGSaYG6UAQqoZvwfHFQGSraz07J73kc8ojE bR0Qkx1BA0l8PGeXd9fOR5K/xktvuwduo0peaQAmiwxPTl90thkCpMuEQORJBZCGodfp Qa9nBURWpVXzv3U6nZPRPT3/xzw8jX6v8nw3O5eBHKY5ueV1jbxt6a55at0dUIlGACpM ViBhMnYT5KTsT3ipzdvIbE+/BjXUxroOR4Y/Bo6tapw1PIFq5zpLRRc6hd/2Z0aQ8NfX /XaEJy+0hEI3PBQBYje4Dy8BccDlwdxuDNBa9FC5V/zosrcUTMZ+vChSpZbEbdKutGe/ OTUw== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=SZQyTe94IeYRNaQ/OjDzBjz8HKY/xj+NSpzFSzeS/Cs=; b=VwHZB/pgAmZHjwRHP5X8iqOFB8PtnrPJAwnOJ5+mFdy6xzMHzat1PbDIjPDip5LRCO 48No03q8hZPUNgIw4IUWmLCLfb3TSH2uYPw3wu4kex7pyxTCb3eoDfE5ddeqDBHa5QY8 nD6UcD5twCB0/UJG6wN5qVBMRpqvi0FL5O/9g8h6nitn1miYFS6Iav9V4Bcgiulw7dmk CAmy5kiXvAPD+QfwskmWg/WIjyHUG6LcGrlH3Ceo60JUohyS7FjCgVm4Eqar7O8tQ/mm rHbwz58eY+HVMYNIs7ySLeNs0TGFeGJv68zlq2w6NqBckptpveXAMflVr6VTkM4Pkh6w mm8g== |
| X-Gm-Message-State | AD7BkJLClr2FGmqZjGRW9eYztMCnFCBbfe+0/GpBL5LEi3FxAWx7JpPfEBliedXhUw0aYkoCu8F/aIG6ezNwVQ== |
| X-Received | by 10.51.17.34 with SMTP id gb2mr4091975igd.13.1457191118657; Sat, 05 Mar 2016 07:18:38 -0800 (PST) |
| In-Reply-To | <56DAF5A7.9080503@rece.vub.ac.be> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:104099 |
Show key headers only | View raw
On Sun, Mar 6, 2016 at 2:05 AM, Antoon Pardon <antoon.pardon@rece.vub.ac.be> wrote: > Using python 3.4/3.5 > > Suppose I have the following class: > > class Tryout: > > @extern > def method(self, ...) > > Now how can I have access to the Tryout class in > the extern function when it is called with method > as argument > > def extern(f): > the_class = ???? > > f.__class doesn't work, if I write the following > > def extern(f) > print(f.__class__) > > the result is: <class 'function'>, so that doesn't work. > Looking around I didn't find an other obvious candidate > to try. Anybody an idea? At the time when the function decorator is run, there isn't any class. You could just as effectively create your function outside the class and then inject it (Tryout.method = method). What is it you're trying to do? Would it be a problem to have a class decorator instead/as well? ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Can I find the class of a method in a decorator. Chris Angelico <rosuav@gmail.com> - 2016-03-06 02:18 +1100
csiph-web