📜  python 将输入保存到文本文件 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:28.936000             🧑  作者: Mango

代码示例2
Simple Mood Diary Script As An Example#

print('My Mood Diary')
mood = input('How are you feeling today? ')
#Saves the input as the variable 'mood'#
text_file = open("MoodDiary.txt", "w")
#Opens or creates the .txt file, sharing the directory of the script#
text_file.write(mood)
#Writes the variable into the .txt file#
text_file.close()
#Closes the .txt file#