我想讓我的代碼縮小列表中的單詞輸入然後將它們排序到不同的列表,但它扔出來這可以幫助我?當創建腳本有:TypeError:'_io.TextIOWrapper'對象是不可訂
Traceback (most recent call last):
File "C:/Users/dan/Desktop/python/threeword.py", line 4, in <module>
word = words[x],words[(x+1)],words[(x+2)]
TypeError: '_io.TextIOWrapper' object is not subscriptable
words=open("three.txt",'r+')
f=open("three1","w")
for x in words:
word = words[x],words[(x+1)],words[(x+2)]
print(word)
input=('y or n')
if input=="y":
f.write(word)
x=x+3
elif input=='stop':
break
else:
x=x+3
f.close()
你期望'單詞[x]'做什麼? –
嘗試使用'zip()'或'next(iterator)'在迭代器類型列表中遍歷多個元素(塊)。見https://stackoverflow.com/questions/16789776/iterating-over-two-values-of-a-list-at-a-time-in-python –