我絕對會把我的頭髮拉出來。該函數中的if/elif語句在elif行上引發語法錯誤。對我來說,沒有明顯的語法問題。Python if/elif語法錯誤...爲什麼
"elif n == cs_index:"
^
SyntaxError: invalid syntax
我試着將它切換成熊「別的:」只是爲了看看這是否愚蠢的話,它沒有。我確定有些事我看不到。
def higherhighlight(cs_index):
text.tag_remove("the hello","1.0", END)
idex = "1.0"
for n in range(cs_index):
if n < cs_index:
idex = text.search("Hello", idex, nocase=1, stopindex=END)
lastidex = idex+"+"+str(len("hello"))+"c"
idex = lastidex
elif n == cs_index:
idex = text.search("Hello", idex, nocase=1, stopindex=END)
print idex
lastidex = idex+"+"+str(len("hello"))+"c"
print lastidex
text.tag_remove("hellos", idex, lastidex)
text.tag_add("the hello", idex, lastidex)
text.tag_config("the hello", background="dark green")
你是否檢查過你的代碼是否正確縮進? – tjohnson
將代碼粘貼到我的IDE後沒有語法錯誤。必須是你的縮進。 –
您是否混合了製表符和空格? – cdarke