2011年6月25日 星期六

Python 對應PHP function 的方式(nl2br、explode、implode)

def nl2br(string, is_xhtml= True ):
    if is_xhtml is True :
        return string.replace('\n','
\n')
    else :
        return string.replace('\n','
\n')

實現explode
>>> str = 'a|b|c|d|e'
>>> str.split("|")
['a', 'b', 'c', 'd', 'e']

實現implode
>>> list = ['a', 'b', 'c', 'd', 'e']
>>> "|".join(list)
'a|b|c|d|e'

GAE is not multi-line

在GAE中如果有多行文字儲存,有\n換行符號
GAE會報錯(is not multi-line)


請對model 加上參數 db.StringProperty(multiline=True)