简体   繁体   中英

python, how to call function in as parameter in self.response.out.write()

class GuestBook(webapp.RequestHandler):
    def post(self):
        self.response.out.write(
            '<h2>You wrote:</h2> %s'   %self.request.get('content')     )

I want to pass this: %self.request.get('content') into a function. And use function return in the old place.I am python newbie. I tried.but failed. need help!

This is my function; I defined it in the same class as below.

def ept(str)
        str = str + " is good."
        return str

And I call it in the old place like:

ept(%self.request.get('content'))

Could anybody help me, what is wrong with my code

First of all you ought to (re-)read about string interpolation

The % is an operator applicable to string and unicode objects, so such an object must precede its usage. So you could do

def ept(s):
    return "%s is good" % s

ept(self.request.get('content'))

% is applicable to integers as well, but that's a different story.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM