Python合並處理字符串的四種方法在這里都有介紹:
http://www.cnblogs.com/heshizhu/archive/2012/01/11/2319892.html
無論使用最簡單的+符號還是是用列表,當遇到字符變量中出現NoneType時,這兩種方法都會出現錯誤,其他兩種方法沒有驗證。Python將[]{}""都作為False處理。那False和str合並肯定不可以的。我猜測NoneType作為python的一種類型,通常我們用if xxxx is None:語句來判斷。那None是不可以作為判斷類型為NoneType的空字符串的標示。有代碼:
tempfinal.append(reftext.text)
tempfinal.append(reftext.tail)
if None in tempfinal:
tempfinal.remove(None)
finaltext = ''.join(tempfinal)
tempfinal是合並用字符串列表,finaltext是最后合並字符串。結果正確。