Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12372
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <chris@rebertia.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'context': 0.04; 'parameter': 0.05; 'convention.': 0.07; 'subject:when': 0.07; 'python': 0.08; 'argument': 0.15; 'subject:use': 0.15; 'given:': 0.16; 'naming': 0.16; 'operator.': 0.16; 'then:': 0.16; 'webapp': 0.16; '\xc2\xa0if': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.16; 'cheers,': 0.18; 'arguments': 0.18; 'slightly': 0.19; 'programming': 0.20; 'cc:no real name:2**0': 0.20; 'seems': 0.20; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'wonder': 0.23; 'received:209.85.213.46': 0.23; 'received:mail- yw0-f46.google.com': 0.23; 'pm,': 0.24; 'variable': 0.24; 'aug': 0.24; "python's": 0.24; 'code': 0.25; 'parameters': 0.25; "i'm": 0.27; 'function': 0.27; 'subject:need': 0.28; 'pass': 0.29; 'explicitly': 0.29; 'message-id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.30; 'match': 0.30; 'implicitly': 0.30; 'semantics': 0.30; 'skip:\xc2 20': 0.30; 'sun,': 0.30; 'class': 0.30; '(e.g.': 0.31; 'equivalent': 0.31; 'subject:?': 0.31; 'chris': 0.32; 'list': 0.32; 'value.': 0.32; '----': 0.32; "what's": 0.33; 'actually': 0.33; 'instead': 0.33; 'however,': 0.34; 'skip:b 40': 0.34; 'test': 0.34; 'languages.': 0.34; 'object': 0.35; 'languages': 0.37; 'passed': 0.37; 'using': 0.37; 'list,': 0.37; 'something': 0.37; 'cases,': 0.38; 'some': 0.38; 'received:google.com': 0.38; '8bit%:8': 0.38; 'received:209.85': 0.38; 'skip:o 20': 0.38; 'subject:: ': 0.39; 'unlike': 0.39; 'else': 0.39; 'define': 0.39; 'called': 0.40; 'background': 0.40; 'where': 0.40; 'you.': 0.62; 'free': 0.63; 'skip:+ 10': 0.64; 'here': 0.65; 'receive': 0.67; 'legal': 0.70; 'why?': 0.73; 'captcha': 0.84; 'sender:addr:chris': 0.84; 'subject:call': 0.91; 'to:none': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:cc:content-type :content-transfer-encoding; bh=9A9/trGE0PzKSfkTtYhbAAiUgS6tEAVGgmCdzzL7UGo=; b=dGGeZDzzrfRDqKymk5gybZF9An2++V7dywWX0Bciw/u2DNKRKCSuic8WpNiE/YYEf2 wc4T8bmCRV5+eKG73pFZnNugXfRDQ6hYjoohX8bmGXS+0eWRj9nJIJRdg1cfg2utNZpU unhK76sFLOipFfT6NIqEMHZ7olO9P4LaVFdFI= |
| MIME-Version | 1.0 |
| Sender | chris@rebertia.com |
| In-Reply-To | <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> |
| References | <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> |
| Date | Sun, 28 Aug 2011 18:52:03 -0700 |
| X-Google-Sender-Auth | ejZRZsB6DZUdCc3H2nmNuNefs8s |
| Subject | Re: Why I need the parameter when the call doesn't use it? |
| From | Chris Rebert <clp2@rebertia.com> |
| Cc | python-list@python.org |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.527.1314582726.27778.python-list@python.org> (permalink) |
| Lines | 62 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1314582726 news.xs4all.nl 2444 [2001:888:2000:d::a6]:51862 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:12372 |
Show key headers only | View raw
On Sun, Aug 28, 2011 at 5:26 PM, Niklas Rosencrantz <niklasro@gmail.com> wrote:
> I modularize code for a webapp and I want to know what python makes that a need to define an argument called self? Here's some code where I'm modularizing a recaptcha test to a function and the I must add the parameter "self" to the function is_submitter_human:
>
> ----
> class A(BaseHandler, blobstore_handlers.BlobstoreUploadHandler):
> def is_submitter_human(self):
> cResponse = captcha.submit( self.request.get('recaptcha_challenge_field').encode('utf-8'), self.request.get('recaptcha_response_field').encode('utf-8'),
> CAPTCHA_PRV_KEY,
> os.environ['REMOTE_ADDR'])
> return cResponse.is_valid
>
> def post(self, view):
> logging.debug('starting recaptcha check')
> isHuman = self.is_submitter_human()# here I don't pass a parameter
> logging.debug('recaptcha check isHuman:' +str(isHuman))
> if not isHuman:#failed captcha and can try again
> #Reprint the form
>
> --
> It seems unlike other programming languages where the number of arguments in the call are the same as the number of arguments in the function head and python requires me to add one parameter to the function head and I wonder if you call tell me something about the background why?
>
> What's the story of using these parameters that are called "self"?
Some other languages name the analogous parameter "this" instead of
"self", and basically declare it implicitly for you. In both cases,
said variable is used to refer to the object that the current method
is being called on (e.g. if `w` is a list and I do w.append(v), the
list `w` is `self` in the context of the .append() method call). Since
Python's object-orientation is slightly impure, you are required to
declare `self` explicitly in the parameter list, unlike most other
languages. Technically, you are free to name the parameter something
else instead of "self"; naming it "self" is merely a convention.
However, no matter its name, the first parameter to a method will
always receive the current object as its argument value.
So, given: x = Foo()
Then: x.bar(y, z)
is approximately equivalent to:
Foo.bar(x, y, z) # perfectly legal working code
So the number of arguments actually /does/ match the number of
parameters; `x`/`self` is just passed implicitly via the semantics of
the dot (".") operator.
Cheers,
Chris
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why I need the parameter when the call doesn't use it? Niklas Rosencrantz <niklasro@gmail.com> - 2011-08-28 17:26 -0700
Re: Why I need the parameter when the call doesn't use it? Ben Finney <ben+python@benfinney.id.au> - 2011-08-29 11:32 +1000
Re: [Python] Why I need the parameter when the call doesn't use it? Chris Gonnerman <chris@gonnerman.org> - 2011-08-28 20:42 -0500
Re: [Python] Why I need the parameter when the call doesn't use it? Ben Finney <ben+python@benfinney.id.au> - 2011-08-29 12:34 +1000
Re: [Python] Why I need the parameter when the call doesn't use it? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-29 14:40 +1000
Re: Why I need the parameter when the call doesn't use it? Chris Rebert <clp2@rebertia.com> - 2011-08-28 18:52 -0700
Re: Why I need the parameter when the call doesn't use it? John Gordon <gordon@panix.com> - 2011-08-29 03:27 +0000
Re: Why I need the parameter when the call doesn't use it? Ben Finney <ben+python@benfinney.id.au> - 2011-08-29 16:15 +1000
csiph-web