Tuesday, January 23, 2018

Writing to file using Python

I have a file called output.txt, which I want to write into from a few functions around the code, some of which are recursive.
Problem is, every time I write I need to open the file again and again and then everything I wrote before is deleted.
I am quite sure there is a solution, didn't find it in all questions asked here before..



def CutTable(Table, index_to_cut, atts, previousSv, allOfPrevSv):
print ('here we have:')

print atts
print index_to_cut
print Table[2]
tableColumn=0
beenHere = False
for key in atts:
with open("output.txt", "w") as f:
f.write(key)



and from another function:



def EntForAttribute(possibles,yesArr):
svs = dict()
for key in possibles:
svs[key]=(yesArr[key]/possibles[key])
for key in possibles:
with open("output.txt", "w") as f:
f.write(key)



All output I have is the last one written in one of the functions..

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...