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 _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor