[英]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') )
我想將這個: %self.request.get('content')
傳遞給一個函數。 並在舊地方使用函數return.I是python newbie。 我嘗試過,但是失敗了。 需要幫忙!
這是我的職責; 我在以下相同的類中定義了它。
def ept(str)
str = str + " is good."
return str
我在舊的地方稱它為:
ept(%self.request.get('content'))
有人可以幫我嗎,我的代碼有什么問題
首先,您應該(重新)閱讀字符串內插法
%
是適用於字符串和unicode對象的運算符,因此此類對象必須先於其使用。 所以你可以做
def ept(s):
return "%s is good" % s
ept(self.request.get('content'))
%
也適用於整數,但這是另一回事。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.