2011-11-04 18 views
0
class GuestBook(webapp.RequestHandler): 
    def post(self): 
     self.response.out.write(
      '<h2>You wrote:</h2> %s' %self.request.get('content') ) 

我想通過這個:%self.request.get('content')到一個函數。並在舊的地方使用函數返回。我是python新手。我試過了,但失敗了。需要幫忙!蟒蛇,如何調用作爲參數self.response.out.write()

這是我的功能;我將它定義在下面的同一個類中。

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

,我把它叫做老地方,如:

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

任何人可以幫助我,什麼是錯我的代碼

回答

1

首先你應該(重新)閱讀大約string interpolation

%是一個適用於字符串和unicode對象的運算符,所以這樣的對象必須先於它的用法。所以,你可以做

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

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

%適用於整數爲好,但是這是一個不同的故事。

+0

謝謝!有用。同樣,在ept()之前需要% –