[Tutor] Can't figure out AttributeError message
Reed L. O'Brien
reed at intersiege.com
Thu Jul 7 19:09:27 CEST 2005
Jim Roush wrote:
>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')
> record_size = struct.calcsize('Lf')
>
> record_number = 0
> for rec in sp500_csv_recs:
> rec.strip('\n')
> sp500_csv_fields = rec.split(',')
>
>
> sp500_csv_date = sp500_csv_fields[0]
> sp500_csv_open = sp500_csv_fields[1]
> sp500_csv_high = sp500_csv_fields[2]
> sp500_csv_low = sp500_csv_fields[3]
> sp500_csv_close = sp500_csv_fields[4]
> sp500_csv_volume = sp500_csv_fields[5]
>
> print 'build:', sp500_csv_date
>
> 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()
>
>
>
>
>
>
>>> sp_rand = ('c:/indices/sp500.rnd', 'w+b')
>>> type(sp_rand)
<type 'tuple'>
you aren't opening sp_500.rnd you are assigning tuple values.
>>> sp_rand = open('c:/indices/sp500.rnd', 'w+b')
>>> type(sp_rand)
<type 'file'>
but you still need to read in values (sp_rand.readlines()) assuming
that's what you want.
~r
--
4.6692916090
'cmVlZG9icmllbkBnbWFpbC5jb20=\n'.decode('base64')
http://www.spreadfirefox.com/?q=affiliates&id=16474&t=1
keyID: 0x0FA09FCE
More information about the Tutor
mailing list