Why I need the parameter when the call doesn't use it?

Niklas Rosencrantz niklasro at gmail.com
Sun Aug 28 20:26:41 EDT 2011


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"?

Thank you



More information about the Python-list mailing list