Answers for "python print context of text"

1

python save input to text file

#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#
Posted by: Guest on August-09-2020
1

how to veiw and edit files with python

#write
f = open('helloworld.txt','wb')
f.write('hello world')
f.close()

#read
f = open('helloworld.txt','r')
message = f.read()
print(message)
f.close()
Posted by: Guest on June-12-2020

Python Answers by Framework

Browse Popular Code Answers by Language