I am a newbie to Python(2.7.15). I am trying to append the output of my Python script to a text file separated by a tab.
Below is part of my code:
for key,value in d.iteritems():
with open('output.txt', 'a') as file:
file.write(key + "\t" + value + "\t")
.....
....
for item in data["response"]["docs"]:
titleValue = (item['title'])
with open('/tmp/output.txt', 'a') as file:
file.write(titleValue + "\n")
My output file looks like below:
FirstKey FirstValue
FirstTitle
SecondKey SecondValue
SecondTitle
Basically I want to print the values as tab separated value in the same line and print the next line as tab separated values in a new line and so on as below:
FirstKey FirstValue FirstTitle
SecondKey SecondValue SecondTitle
How can I do that? file.write is printing it in a new line. I want it to print in the same line
with open.... Also, researchforloops to see how to iterate over multiple controls simultaneously.