python输出内容到本地txt文件

如果要写入一些不是字符串的东西, 那么将需要先进行转换:

实例

#!/usr/bin/python3

# 打开一个文件
f = open("/tmp/foo1.txt", "w")

value = ('www.runoob.com', 14)
s = str(value)
f.write(s)

# 关闭打开的文件,必须关闭不然电脑能炸裂
f.close()

猜你喜欢

转载自www.cnblogs.com/StarZhai/p/12058177.html