hello

can someone please advise as to how can i insert tab after every word while inputting it in a file?

i have to read all the lines in a file. the file has tables. there are random spaces between the words. Output is to put this table to another file in tab delimited formated ( one tab between columns).
i have read the lines using readlines() and split the lines. I need to output this in the other file. For that, i need to put tab after every word.
Kindly suggest how do i do it?

thanks!

Recommended Answers

All 2 Replies

Use split and then join:

s = "abc def   ghi     jkl"
split_s = s.split()
print "\t".join(split_s)
s = "abc def ghi  jkl"
Print("\t".join(s.split())

Or

print("Hello \t world")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.