0

我試圖創建一個web應用程序(通過GAE)的「迭代」是需要輸入一個「模板」的字符串,兩個整數(創建範圍),以及單詞列表。用戶將插入一個「#」到他們想去的地方的數字要遍歷字符串,並在那裏他們希望被遍歷的話字符串中「@」。發電機表情和谷歌應用程序引擎

輸入:

template string: "Person#[email protected]" 
starting integer: 1 
ending integer: 3 
list of words: "Apples, Bananas, Oranges" 

輸出:

Person1LikesApples 
Person1LikesBananas 
Person1LikesOranges 
Person2LikesApples 
Person2LikesBananas 
Person2LikesOranges 
Person3LikesApples 
Person3LikesBananas 
Person3LikesOranges 

我所要的輸出本身顯示結果的文本框,當用戶點擊標題爲「下一個」或類似的東西一個提交按鈕。踢球者是我希望輸出僅在第一次單擊按鈕時顯示Person1的項目。然後,他們第二次點擊它,只有Person2的項目出現,等等。

我寫了一個簡單的小Python程序有發電機,但我有併入我的谷歌App Engine應用程序這個麻煩。

這裏是我的功能:

def g(f, text, lower, upper, list): 
    for num in range(int(lower),int(upper)+1): 
     yield f(text.replace('#', str(num)), list) 

def f(text, list): 
    for i in list: 
     print text.replace('@', i) 

和其他代碼:

if text and lower and upper and words: 
    result = g(f, words, lower, upper, list) 
    self.render_iterator(result=next(result)) 

(^此代碼返回「無」在我的結果的文本框,當我填寫其他值,但不承認它作爲發電機表情時,我周圍做一個小擺弄)

是否有另一種方式做到這一點,我很想念?我應該使用GQL和Google Datastore嗎?如果您需要查看更多我的代碼,請告訴我。

謝謝!

回答

1

我建議搞清楚如何先做此之外的App Engine。這是一個非常簡單的編程問題,但如果你很難搞清楚,試圖在網絡應用程序內部做的只是折磨。一旦您對解決方案感到滿意,您可以將其應用於App Engine。

0

f()沒有返回值,因此返回None。您需要更改

print text.replace('@', i) 

return text.replace('@', i) 
+0

現在我得到的是詞作爲輸出的列表。 – bmay2

+0

不知道這是否有幫助,但我在GAE日誌中收到此消息: WARNING 2012-06-02 03:26:54,550 py_zipimport.py:139]無法打開zipfile /Library/Frameworks/Python.framework/版本/ 2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info:IOError:[Errno 13] file not accessible:'/Library/Frameworks/Python.framework/Versions/2.7 /lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info」 – bmay2