File I/O

Klaas mike.klaas at gmail.com
Wed May 9 20:36:59 EDT 2007


On May 9, 2:43 pm, HMS Surprise <j... at datavoiceint.com> wrote:
> > [lst.append(list(line.split())) for line in file]
>
> Thanks, this is the direction I wanted to go, BUT I must use v2.2 so
> the line above gives me the error:
>
> AttributeError: __getitem__
>
> But the write format will be helpful.

(change to file.xreadlines(). Btw that snippet will fail miserably for
most data).

Instead, use pickle:

import pickle
pickle.dump(lst_of_lst, open('outfile', 'wb'))
lst_of_lst = pickle.load(open('outfile', 'rb'))

-Mike




More information about the Python-list mailing list