[Tutor] Can't figure out AttributeError message

Brian van den Broek bvande at po-box.mcgill.ca
Thu Jul 7 19:11:33 CEST 2005


Jim Roush said unto the world upon 07/07/2005 12:42:
> I'm getting the following error message:
> 
>       AttributeError: 'tuple' object has no attribute 'seek'
> 
> below is the code that produced the error.  The line in question is 
> marked with arrow in the left margin.  Any help would be appreciated. 
> 
> def build_sp500_rand():
>     sp500_csv = open('c:/indices/sp500.csv', 'r')
>     sp500_csv_recs = sp500_csv.readlines()
>     sp500_csv.close()
>    
>     sp_rand = ('c:/indices/sp500.rnd', 'w+b')

Here is the problem. sp_rand is a tuple of 2 strings, not a file 
object. Try
       sp_rand = open('c:/indices/sp500.rnd', 'w+b')
or
       sp_rand = file('c:/indices/sp500.rnd', 'w+b')



>     record_size  = struct.calcsize('Lf')
> 
>     record_number = 0
>     for rec in sp500_csv_recs:

<snip some code from for loop>

>         buffer = struct.pack('Lf', long(sp500_csv_date), 
> float(sp500_csv_close))
> ====>   sp_rand.seek(record_number * record_size)
>         sp_rand.write(buffer)
>        
>         record_number = record_number + 1
>        
>     sp_rand.close()

HTH,

Brian vdB




More information about the Tutor mailing list