Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20889
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <chris@rebertia.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python': 0.08; '-------': 0.09; 'executed': 0.09; 'linux.': 0.09; 'object;': 0.09; 'output': 0.10; 'am,': 0.12; "'orange',": 0.16; "'rb')": 0.16; '4321': 0.16; 'nest': 0.16; 'objects?': 0.16; 'output)': 0.16; 'subject: ..': 0.16; 'subject:handling': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'cheers,': 0.20; 'cc:no real name:2**0': 0.21; 'header:In-Reply-To:1': 0.22; 'feb': 0.22; 'received:209.85.212.46': 0.23; 'received:mail- vw0-f46.google.com': 0.23; 'fine': 0.24; 'cc:2**0': 0.26; 'code': 0.26; 'import': 0.27; '-----': 0.28; 'repeatedly': 0.28; 'message- id:@mail.gmail.com': 0.29; 'print': 0.29; 'cc:addr:python.org': 0.29; 'sun,': 0.30; 'chris': 0.30; 'that,': 0.32; 'objects': 0.32; 'received:209.85.212': 0.33; 'object': 0.33; 'skip:# 10': 0.34; 'but': 0.37; 'received:google.com': 0.37; 'either': 0.37; 'received:209.85': 0.38; 'skip:o 20': 0.38; 'received:209': 0.39; 'header:Received:6': 0.61; 'below': 0.62; '26,': 0.73; '(once': 0.84; 'received:10.220': 0.84; 'sender:addr:chris': 0.84 |
| Received-SPF | pass (google.com: domain of chris@rebertia.com designates 10.220.151.67 as permitted sender) client-ip=10.220.151.67; |
| Authentication-Results | mr.google.com; spf=pass (google.com: domain of chris@rebertia.com designates 10.220.151.67 as permitted sender) smtp.mail=chris@rebertia.com; dkim=pass header.i=chris@rebertia.com |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=voORgnAHfgaPNSn4Sk3aKRlIBYfRncoUhNurNY7Vv2A=; b=aQyVFunwIdiZYPN6ahU3NBdm5p3xXVaq9uAxqRyZUTluFXTLsxucRkxoEwyu9XjnSb wrfPtCVdP7ZDT7uTHSBbKVtBRcwlvHL/9Ir7cTPgRlb5jHLxODreF6UvF6h5kf6ISY55 CtovVg3CLzPdzBBXaG6XpxC0miwc6OD8rGrWo= |
| MIME-Version | 1.0 |
| Sender | chris@rebertia.com |
| In-Reply-To | <CAJ1erZ0s-aEzD_uYqY4=bhbwAkBRykXD72Lfx7bCmecRDazhAw@mail.gmail.com> |
| References | <CAJ1erZ0s-aEzD_uYqY4=bhbwAkBRykXD72Lfx7bCmecRDazhAw@mail.gmail.com> |
| Date | Sun, 26 Feb 2012 03:58:18 -0800 |
| X-Google-Sender-Auth | qAyw2gPbh_7W99PGbfsrM4JHz4Y |
| Subject | Re: pickle handling multiple objects .. |
| From | Chris Rebert <clp2@rebertia.com> |
| To | Smiley 4321 <ssmile03@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-Gm-Message-State | ALoCoQnkICCNwvyof0z37UDoyGHlAxsIO1XyBLzX/NXvO/CbotIfsCo1cTKso5sdhWD2XfIUeYdj |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.175.1330257507.3037.python-list@python.org> (permalink) |
| Lines | 35 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1330257507 news.xs4all.nl 6952 [2001:888:2000:d::a6]:40285 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:20889 |
Show key headers only | View raw
On Sun, Feb 26, 2012 at 3:25 AM, Smiley 4321 <ssmile03@gmail.com> wrote:
> If I have a sample python code to be executed on Linux. How should I handle
> multiple objects with 'pickle' as below -
>
> -------
> #!/usr/bin/python
>
> import pickle
>
> #my_list = {'a': 'Apple', 'b': 'Mango', 'c': 'Orange', 'd': 'Pineapple'}
> #my_list = ('Apple', 'Mango', 'Orange', 'Pineapple')
> my_list = ['Apple', 'Mango', 'Orange', 'Pineapple']
> #my_list = ()
> output = open('readfile.pkl', 'wb')
> pickle.dump(my_list, output)
> output.close()
>
> my_file = open('readfile.pkl', 'rb')
> my_list2 = pickle.load(my_file)
> my_file.close()
>
> print my_list
> print my_list2
> -----
>
> This code works fine but now I have to handle multiple objects?
You can either nest the multiple objects inside a single compound
object and just (un)pickle that, or you call call dump()/load()
repeatedly (once per object; yes, this works).
Cheers,
Chris
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: pickle handling multiple objects .. Chris Rebert <clp2@rebertia.com> - 2012-02-26 03:58 -0800
csiph-web