Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72891 > unrolled thread
| Started by | Ben Finney <ben@benfinney.id.au> |
|---|---|
| First post | 2014-06-07 10:28 +1000 |
| Last post | 2014-06-07 10:28 +1000 |
| 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.
Re: Decorating one method of a class C with another method of class C? Ben Finney <ben@benfinney.id.au> - 2014-06-07 10:28 +1000
| From | Ben Finney <ben@benfinney.id.au> |
|---|---|
| Date | 2014-06-07 10:28 +1000 |
| Subject | Re: Decorating one method of a class C with another method of class C? |
| Message-ID | <mailman.10838.1402100900.18130.python-list@python.org> |
Dan Stromberg <drsalists@gmail.com> writes: > Is there a way of decorating method1 of class C using method2 of class > C? Can you give a concrete example (i.e. not merely hypothetical) where this would be a useful feature (i.e. an actual improvement over the absence of the feature), and why? > It seems like there's a chicken-and-the-egg problem; the class doesn't > seem to know what "self" is until later in execution so there's > apparently no way to specify @self.method2 when def'ing method1. You're referring specifically to instance methods, it seems. Right, there's no instance *of* the class during the *definition* of the class, so ‘self’ can't refer to such an instance. Also, an instance method needs to get the instance as the first parameter, whereas the decorator must accept the to-be-decorated function as its argument. So I don't see what you're trying to achieve, rather than the more straightforward and clearer use of a decorator function which *isn't* a method in the same class. Can you show a Simple, Self-Contained Complete Example to show us what you're trying to do? More importantly, why you think it should be done this way? -- \ “Visitors are expected to complain at the office between the | `\ hours of 9 and 11 a.m. daily.” —hotel, Athens | _o__) | Ben Finney
Back to top | Article view | comp.lang.python
csiph-web