创建文本文档 (Python) [英] Create Text Document (Python)

查看:51
本文介绍了创建文本文档 (Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想用用户输入的代码创建一个名为 spam.txt 的文档.假设我有用户输入,比如:

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?

推荐答案

f = open('file.txt','w')
a = input('is python good?')
f.write('answer:'+str(a))
f.close()

容易吗?:)

这篇关于创建文本文档 (Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆