我想在Python中編寫一些東西,它只是從字符串輸入中刪除任何HTML標記。但由於某種原因,代碼將無法執行(簡單地掛起)在我的家庭Python安裝,並在Udacity界面上被殺死。Python中的基本搜索和替換不是執行
我哪裏錯了?
def remove_tags(sentence):
list = []
state = 0
while state == 0:
location1 = sentence.find('<')
location2 = sentence.find('>',location1)
if location1 != -1:
chamber = sentence[location1:location2+1]
sentence.replace(chamber,'')
elif location1 == -1:
state = 1
return sentence.split()
return sentence.split()
print remove_tags('''<table cellpadding='3'>
<tr><td>Hello</td><td>World!</td></tr>
</table>''')
謝謝!問題解決了。;) – c3ntury