问题
Lets say I want to create a document out of user-inputted code, called spam.txt. Assuming I have the user input, say:
input("Is Python Good? ")
How can I save the text, that the user inputted, to a text file, and can one do this?
回答1:
f = open('file.txt','w')
a = input('is python good?')
f.write('answer:'+str(a))
f.close()
Easy no? :)
回答2:
with open('spam.txt', 'a') as f:
f.write(string_output)
来源:https://stackoverflow.com/questions/9284507/create-text-document-python