如何使用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

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))

不太清楚你的意思