Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74810
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.023 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'say,': 0.05; '(python': 0.07; 'decorator': 0.09; 'must,': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'context;': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'func': 0.16; 'magic': 0.16; 'newsgroups': 0.16; 'simple.': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'passing': 0.19; 'example': 0.22; 'cc:addr:python.org': 0.22; 'instance,': 0.24; 'cc:2**0': 0.24; 'define': 0.26; 'mention': 0.26; 'pass': 0.26; 'header:In-Reply- To:1': 0.27; 'function': 0.29; 'forgot': 0.30; 'message- id:@mail.gmail.com': 0.30; 'lists': 0.32; 'another': 0.32; 'text': 0.33; 'could': 0.34; 'subject:with': 0.35; 'created': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'google': 0.35; 'so,': 0.37; 'two': 0.37; 'pm,': 0.38; 'quote': 0.39; 'mailing': 0.39; 'how': 0.40; 'read': 0.60; 'worry': 0.60; 'information,': 0.61; 'first': 0.61; "you'll": 0.62; 'refer': 0.63; 'articles': 0.65; 'life': 0.66; 'skill': 0.68; 'internet': 0.71; 'jul': 0.74; 'avoids': 0.84; 'decorate': 0.84; 'to:none': 0.92 |
| 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 :content-type; bh=PrUcL4qhMV2R+N5e0KSt/CcYUR1shynS/0BIW3YFoZA=; b=Ek4DeLMySx48pk0+rFH6zoGqKyC2rtNsRaFOXTHG9s7gBOhHWLjVJEm+1SzX5N5G7E oxJDDThs3tSTW/lwx7rg7g2NTCPKI0Ma0ao7ZEXwO9x7ZTur1oWivEfaf00YWW4mnWCp 9C7hazoUGqaYSdXEn/+XZdOu3kr8Aqmp6HPUBWy014tZ0d6mAgUyr/p4j0hoObLMxYJR Vlxmo4kx6FMaRi8zhEHSZiS6GXSh+vFRGmVSXnE+W7YngGMpsLDkDNkEdilqhansWnWe O264z+p+VJvt7yVrI5PGI6iSHZeP0No+AhJ4EWz3Zxj1ZlHpXheOLo/RpqR3g/E/ZCxh T8WQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.52.138.209 with SMTP id qs17mr598379vdb.80.1405770642180; Sat, 19 Jul 2014 04:50:42 -0700 (PDT) |
| In-Reply-To | <d45c2447-4dc8-47f1-b6fd-df5e1618fc77@googlegroups.com> |
| References | <99846e1f-1ec1-4ed4-9ad4-5c8377b2e1f6@googlegroups.com> <d45c2447-4dc8-47f1-b6fd-df5e1618fc77@googlegroups.com> |
| Date | Sat, 19 Jul 2014 21:50:42 +1000 |
| Subject | Re: Confused with Functions and decorators |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12040.1405770644.18130.python-list@python.org> (permalink) |
| Lines | 30 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1405770644 news.xs4all.nl 2924 [2001:888:2000:d::a6]:42639 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:74810 |
Show key headers only | View raw
On Sat, Jul 19, 2014 at 9:40 PM, Jerry lu <nicholascannon1@gmail.com> wrote:
> oh yeah i forgot about the decorators. Um say that you wanted to decorate a function with the outer() func you would just put @outer on top of it? And this is the same as passing another func into the outer func?
>
> and also with the first example you say x is in the scope when is was created can you define x in the outer func and refer to it in the inner func?
Firstly, please don't use Google Groups, or if you must, please clean
up its messes. It's conventional on mailing lists and newsgroups to
quote a bit of text to give context; so, for instance, you mention one
of my examples, without quoting it.
Secondly: Don't worry about decorators. You almost never need them,
and they're very simple. (Python avoids magic whenever it can!) These
two are equivalent:
def inner():
pass
inner = outer(inner)
@outer
def inner():
pass
That's all the decorator does. It's that simple.
As to scoping... read up on closures. There's a lot that I could say,
but you'll find some excellent articles on the internet about it.
Also, you'll learn how to find information, which is a skill you are
going to need in this life :)
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Confused with Functions and decorators Jerry lu <nicholascannon1@gmail.com> - 2014-07-19 03:52 -0700
Re: Confused with Functions and decorators Chris Angelico <rosuav@gmail.com> - 2014-07-19 21:03 +1000
Re: Confused with Functions and decorators Jerry lu <nicholascannon1@gmail.com> - 2014-07-19 04:40 -0700
Re: Confused with Functions and decorators Chris Angelico <rosuav@gmail.com> - 2014-07-19 21:50 +1000
Re: Confused with Functions and decorators Wojciech Giel <wojtekgiel@gmail.com> - 2014-07-19 13:44 +0100
Re: Confused with Functions and decorators CHIN Dihedral <dihedral88888@gmail.com> - 2014-07-21 00:30 -0700
Re: Confused with Functions and decorators Steven D'Aprano <steve@pearwood.info> - 2014-07-21 07:45 +0000
Re: Confused with Functions and decorators Jerry lu <nicholascannon1@gmail.com> - 2014-07-19 05:01 -0700
Re: Confused with Functions and decorators Wojciech Giel <wojtekgiel@gmail.com> - 2014-07-19 13:06 +0100
Re: Confused with Functions and decorators Wojciech Giel <wojtekgiel@gmail.com> - 2014-07-19 13:10 +0100
Re: Confused with Functions and decorators Jerry lu <nicholascannon1@gmail.com> - 2014-07-19 19:24 -0700
Re: Confused with Functions and decorators Chris Angelico <rosuav@gmail.com> - 2014-07-20 12:27 +1000
Re: Confused with Functions and decorators Jerry lu <nicholascannon1@gmail.com> - 2014-07-19 19:33 -0700
Re: Confused with Functions and decorators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-20 06:41 +0000
csiph-web