如何使用python写入文本文件? [英] how to write to a text file using python ?

查看:76
本文介绍了如何使用python写入文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试输出一个完整的迭代.输出应该在一个文本文件中.我应该如何编码?

I am trying to output a full for iteration. The output should be in a text file. How should I code for that ?

输出应如下所示:

迭代 1 值 -------->val1<标签 >val2<标签 >val3

Iteration 1 values --------> val1 < tab > val2 < tab > val3

迭代2个值-------->val4<标签 >val5<标签 >val6

Iteration 2 values --------> val4 < tab > val5 < tab > val6

这不是很多信息,但我不知道从哪里开始,任何人可以告诉我吗??在基本的我应该如何打开一个文本文件并尝试使用制表符书写 ??

This is not much of an information but I don't know where to start , can any1 show me plz ?? At the basic how should I open a text file and try and write using tabs ??

推荐答案

numbers = [1,2,3,4,5,6]

with open('output.txt', 'w') as f:
  f.write('\t'.join(numbers))

不太清楚你的意思

这篇关于如何使用python写入文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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