Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
664 views
in Technique[技术] by (71.8m points)

how to write to a text file using python ?

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

The output should look like :

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
numbers = [1,2,3,4,5,6]

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

Not really sure what else you mean


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...