简体   繁体   English

python,如何在self.response.out.write()中作为参数调用函数

[英]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. 我想将这个: %self.request.get('content')传递给一个函数。 And use function return in the old place.I am python newbie. 并在旧地方使用函数return.I是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. %是适用于字符串和unicode对象的运算符,因此此类对象必须先于其使用。 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. %也适用于整数,但这是另一回事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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