Answers for "how to save string in text file python"

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

print in text file python

price = 33.3
with open("Output.txt", "w") as text_file:
    text_file.write("Purchase Amount: %s price %f" % (TotalAmount, price))
Posted by: Guest on May-15-2020
1

save python output to text file

$ python my_program.py > output.txt
Posted by: Guest on August-28-2020

Code answers related to "how to save string in text file python"

Python Answers by Framework

Browse Popular Code Answers by Language