[Tutor] attribute error - quick addition

Alan Gauld alan.gauld at btinternet.com
Mon Jul 30 02:00:12 CEST 2007


"Sara Johnson" <sarliz73 at yahoo.com> wrote

> Sorry...I forgot a few more lines at the end of the code.  Starts 
> with "outfile2write..."
> I also added outfile2.sort()

OK, at leasrt we see where the error occcurs. The problem emains that 
you are
trying to sort a file which doesn't have a sort method. You need to 
sort the data
before saving it.

Alan G.


================
outfile2=open('missmeas.dat','w')
for key in skeys:
        fracmiss=1.*numberMissing(z[key].values())/nsites
        outstring="%s has %4.1f%% missing" % (key,100*fracmiss)
        if fracmiss>0.:
                print outstring

        outfile2.write(outstring+'\n') #notice explicit newline \n
outfile2.sort()
outfile2.close()





More information about the Tutor mailing list