string - python appending lists, saving as text, and losing "\t"format -


i have code after every loop iteration appends line of results list. results correspond people (lets "bill") , bill ends list (statsg) of size 3 results. use np.reshape (gives string624 of size (1,3)) when save statsg txt file 1 line (bill 1 2 3 4). within larger loop iterates through patients (lets "bill","jane", "susan"). want append each patient's info form can save readable text file (bill 1 2 3 4 susan 1 5 2 6 jane 5 2 6 7)

the code (which i've tried writing 50 different way) gives me great looking statsg file, globalstats file has each line bracketed [['text']] , tabs ("\t") stay \t [['blahblah\tblahblah]]. i'm changing type lot i'm sure thats screwing up. thoughts?

  statsg.append(str(diameter_glob[1]-diameter_glob[0])+"\t"+str(100*(diameter_glob[1]-diameter_glob[0])/diameter_glob[1])+"\t"+str(pval[1]))     statsg2=np.reshape(statsg,(1,3))      np.savetxt(path+'stats.txt',statsg2,'%s')     globalstats.append(str(start)+"\t"+str(stop)+"\t"+str(statsg2)) np.savetxt('/volumes/old/results.txt',globalstats, '%s') 

the

to turn list string, don't use str(mylist), that's responsible adding brackets , turning tab characters \t. instead use join, e.g. put tab between each string in list: '\t'.join(mylist).


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -