loops - python: append to end of first line in a text file -
i have loop ending in
statsg.append(str(mean))
and after loop
np.savetxt(path+'stats.txt',statsg,'%s')
so after 2 iterations text file 2 lines of text in stats.txt
file. i'd prefer have 1 line of text (i.e. second iteration of loop appends end of first iterations output.
your question not clear, can initiate empty string before loop, in each iteration append it.
string_to_save = '' line in file: string_to_save += line save_function(file_name, string_to_save)
if not helpful edit question more details asked in comments.
Comments
Post a Comment