[Tutor] attribute error - quick addition

Tiger12506 keridee at jayco.net
Tue Jul 31 00:42:47 CEST 2007


> Thanks Alan and Kent (for the sorting notes)!
>
> Alan...I guess I thought outfile2 had data.  { i.e., 
> outfile2=open('missmeas.dat','w') }

Argghh!!! No, no, no! Attribute Error! No matter how much data you have in 
the file, you will *never* be able to call sort on it, because file objects 
do not understand sort. They do not have the "attribute" called "sort". 
Lists have sort. If you want to sort them like you are trying, you will have 
to convert the file into a list (of lines).

lst = list(outfile2)
lst.sort()


JS


> My mistake.
>
> Thanks,
> Sara



More information about the Tutor mailing list