I have a program in python that produce some text plus one number for each line. I want to save it to a file. here example of output after saving:
some text 6.2
some other text 7.6
some other text here too 6.8
some text 8
as you can see the numbers is not in one columns. I used some spaces between texts and numbers but I want put all numbers in one column. how can I do that? with file write method or any other thing?
Edit:
I want to place those numbers in one column to save in a file and with write method. it's very easy if I could use print function to display data in monitor but I want to save in a file. other similar posts show how to display in output not save in a file.
import json
import urllib.request as rq
def func():
data=rq.urlopen('http://yts.to/api/v2/list_movies.json?quality=3d&limit=50')
dataj=json.loads(data.read().decode())
with open('yts.txt','w+') as f:
f.write("Title Imdb rating\n")
f.write("---------------------------------------\n")
for i in range(len(dataj["data"]["movies"])):
f.write(dataj["data"]["movies"][i]["title"]+'\t'+str(dataj["data"]["movies"][i]["rating"]))
f.write("\n")
if __name__=="__main__":
func()