Create a text document (Python)

Suppose I want to create a document from user-entered code called spam.txt. Assuming I have user input, say:

input("Is Python Good? ") 

How can I save the text that the user entered into a text file, and can this be done?

+8
python text save
source share
2 answers
 f = open('file.txt','w') a = input('is python good?') f.write('answer:'+str(a)) f.close() 

Easy no? :)

+19
source share
 with open('spam.txt', 'a') as f: f.write(string_output) 
+8
source share

All Articles