1. 程式人生 > >replace替換不成功問題

replace替換不成功問題

with open("%sindex.html" % (dir), "wb") as code:
    html = html.replace('師師', '研')
    html = html.replace('師師', '學')
    print html

今天遇到一個很蠢的問題,替換不了目標檔案中的字串:

結果原因是沒有賦值!

注意:

Replace這個函式並不直接操作傳入的字串
而是返回一個字串

你得把返回的字串賦值給某個字串啊,不要直接丟棄