Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Excel Question
#9
(Jan-05-2018, 09:27 PM)Gribouillis Wrote: Here is a basic example of writing such a pickle file. Use it once with WRITE = True to create the file foo.pkl, then use it as many times as you need with WRITE = False to use the data.
from collections import namedtuple
import pickle

Record = namedtuple('Record', "id foo bar baz")

WRITE = False


if WRITE:
    L = [Record(i, "a"*100, "b" * 50, "c" * 50) for i in range(30000)]
    print('Writing')
    with open('foo.pkl', 'wb') as ofh:
        pickle.dump(L, ofh)
else:
    print('Reading')
    with open('foo.pkl', 'rb') as ifh:
        L = pickle.load(ifh)
print(len(L))
print(L[17865])

Wow, thanks for this! I'm about to start working on it and this will be a huge help. This will be my first functional Python program, so I'm sure I'll be posting a billion more questions over the next few hours...

P.S. I'm totally new on these forums. Is there a good way to reply or tag someone without quoting their entire message?
Reply


Messages In This Thread
Excel Question - by karaokelove - Jan-05-2018, 05:45 PM
RE: Excel Question - by hshivaraj - Jan-05-2018, 06:04 PM
RE: Excel Question - by karaokelove - Jan-05-2018, 06:08 PM
RE: Excel Question - by Povellesto - Jan-05-2018, 06:24 PM
RE: Excel Question - by karaokelove - Jan-05-2018, 06:31 PM
RE: Excel Question - by Gribouillis - Jan-05-2018, 07:41 PM
RE: Excel Question - by karaokelove - Jan-05-2018, 09:03 PM
RE: Excel Question - by Gribouillis - Jan-05-2018, 09:27 PM
RE: Excel Question - by karaokelove - Jan-05-2018, 09:35 PM
RE: Excel Question - by Gribouillis - Jan-05-2018, 09:38 PM
RE: Excel Question - by karaokelove - Jan-05-2018, 09:46 PM
RE: Excel Question - by snippsat - Jan-05-2018, 11:15 PM
RE: Excel Question - by karaokelove - Jan-05-2018, 11:17 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020