這是我的代碼1.4.3上的文件
sentext = open("urSentence.txt", "w")
UserSen = input("Enter your sentence of your choice, ")
print (UserSen)
sentext.close()
postext = open("ThePos.txt", "w")
listSplit = UserSen.split()
X = {} #this will make the words in a sentence assigned to a number
position=[]
for i,j in enumerate(listSplit): #"i" will count how many words there are in the sentence
if j in X:
position.append(X[j])
else:
X[j]=i
position.append(i)
print (position)
postext.close()
它使文件,但它不保存其中的任何東西。我究竟做錯了什麼?
不保存* *什麼上呢?你從不寫任何東西或從文件中讀取任何東西。 – jonrsharpe
你只是打開和關閉文件 – 0xtvarun
f.write('This is a test \ n')用這個來保存文件裏面的文字 – Hikaryu