我试图让我的用户输入保存但是,当我尝试这样做时,此消息出现在 python shell 中:
nf.write('\n'.join(tempword))
io.UnsupportedOperation: not writable
这是我该部分的代码:
clues_list=[]
userInput=input("Enter a symbol you would like to replace:")
userInput2=input("What letter would you like to replace it with:")
for word in words_list:
tempword = (word)
tempword = tempword.replace('#','A')
tempword = tempword.replace('*', 'M')
tempword = tempword.replace('%', 'N')
tempword=tempword.replace(userInput,userInput2)
print(tempword)
clues_list.append(tempword)
with open('words.txt', 'r') as nf:# bit that isnt working
nf.write('\n'.join(tempword))
基本上,我希望显示用户输入,但这并没有发生。有人可以向我解释为什么以及我需要做些什么来解决它吗?问候