Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20938
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <dihedral88888@googlemail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.020 |
| X-Spam-Evidence | '*H*': 0.96; '*S*': 0.00; 'handler': 0.04; 'unrecognized': 0.07; 'python': 0.08; 'absent': 0.09; 'correct.': 0.09; 'though:': 0.09; 'throw': 0.09; 'to:addr:comp.lang.python': 0.09; 'exception': 0.12; 'defaults.': 0.16; 'fruit': 0.16; 'ignored,': 0.16; 'subject: ..': 0.16; 'subject:handling': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'loading': 0.18; 'wrap': 0.18; 'cc:no real name:2**0': 0.21; 'header:In-Reply- To:1': 0.22; 'feb': 0.22; '(b)': 0.23; 'accidentally': 0.23; 'dictionary': 0.23; 'fine': 0.24; 'cache': 0.24; 'elements': 0.24; 'seconds': 0.26; 'cc:2**0': 0.26; 'code': 0.26; 'bit': 0.28; 'weird': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'sun,': 0.30; 'from:addr:googlemail.com': 0.31; 'header:User-Agent:1': 0.33; 'file': 0.34; 'anything': 0.34; '(a)': 0.34; 'keys': 0.34; 'safely': 0.34; 'something': 0.35; 'received:209.85.214': 0.36; 'two': 0.36; 'sequence': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'some': 0.38; 'think': 0.38; 'data': 0.38; 'sometimes': 0.38; 'received:209': 0.39; 'might': 0.40; "you'll": 0.61; 'more': 0.61; 'your': 0.61; 'course,': 0.62; 'zip': 0.62; 'chance': 0.62; 'love': 0.63; 'guarantee': 0.66; 'maximum': 0.66; 'crash': 0.67; '26,': 0.73; '8bit%:62': 0.77; '11:04': 0.84; '97%': 0.84; 'drinking': 0.84; 'otten': 0.84; 'skip:2 50': 0.91; 'absolutely': 0.98 |
| Received-SPF | pass (google.com: domain of dihedral88888@googlemail.com designates 10.68.199.166 as permitted sender) client-ip=10.68.199.166; |
| Authentication-Results | mr.google.com; spf=pass (google.com: domain of dihedral88888@googlemail.com designates 10.68.199.166 as permitted sender) smtp.mail=dihedral88888@googlemail.com |
| Newsgroups | comp.lang.python |
| Date | Mon, 27 Feb 2012 06:00:22 -0800 (PST) |
| In-Reply-To | <mailman.178.1330261239.3037.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=112.105.143.185; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw |
| References | <CAJ1erZ0s-aEzD_uYqY4=bhbwAkBRykXD72Lfx7bCmecRDazhAw@mail.gmail.com> <jid71t$eh6$1@dough.gmane.org> <mailman.178.1330261239.3037.python-list@python.org> |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| MIME-Version | 1.0 |
| Subject | Re: pickle handling multiple objects .. |
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
| To | comp.lang.python@googlegroups.com |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| 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> |
| Message-ID | <mailman.197.1330351225.3037.python-list@python.org> (permalink) |
| Lines | 42 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1330351225 news.xs4all.nl 6924 [2001:888:2000:d::a6]:36813 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:20938 |
Show key headers only | View raw
在 2012年2月26日星期日UTC+8下午9时00分31秒,Chris Angelico写道:
> On Sun, Feb 26, 2012 at 11:04 PM, Peter Otten <__peter__@web.de> wrote:
> > This is however a bit errorprone. If you accidentally write the loading code
> > as
> >
> > fruit, beverages, vegetables = pickle.load(f)
> >
> > you'll end up drinking potatoes.
>
> You mean vodka? :)
>
> Additionally, you'll get a weird crash out of your program if load()
> returns something other than a sequence of length 3. Remember,
> everything that comes from outside your code is untrusted, even if you
> think you made it just two seconds ago.
>
> Of course, sometimes that exception is absolutely correct. If you wrap
> all this in an exception handler that gives some reasonable behaviour
> - which might even be "terminate the program with a traceback", which
> is the default - then it's fine to let it throw on failure, and
> anything else is just a waste of effort. But for maximum
> extensibility, you would want to make it so that you can add more
> elements to what you save without your code breaking on an old save
> file - and that's where the dictionary is far better. A slight tweak,
> though:
>
> data = pickle.load(f)
> fruit = data.get("fruit",[])
> beverages = data.get("beverages",[])
> vegetables = data.get("vegetables",[])
>
> With this, you guarantee that (a) unrecognized keys will be safely
> ignored, and (b) absent keys will quietly go to their given defaults.
>
> ChrisA
I love python for pickle and zip lib build in. I write programs that
stay in the L1 or L2 cache of the CPU > 97% percent of chance of nontrivial executions.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: pickle handling multiple objects .. Chris Angelico <rosuav@gmail.com> - 2012-02-27 00:00 +1100 Re: pickle handling multiple objects .. 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-27 06:00 -0800 Re: pickle handling multiple objects .. 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-27 06:00 -0800
csiph-web