Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51322
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ramit.prasad@jpmorgan.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'parameters': 0.04; 'attribute': 0.07; 'completeness': 0.07; '__init__': 0.09; 'received:155': 0.09; 'ron': 0.09; 'api': 0.11; "'w')": 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'dump': 0.16; 'from:addr:jpmorgan.com': 0.16; 'mylist': 0.16; 'received:155.180': 0.16; 'received:159': 0.16; 'received:159.53': 0.16; 'received:159.53.110': 0.16; 'received:169.70': 0.16; 'received:169.70.190': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'securities,': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'file,': 0.19; '>>>': 0.22; 'import': 0.22; 'to:name:python-list@python.org': 0.22; 'print': 0.22; 'this?': 0.23; 'header:Received:8': 0.24; 'skip:" 30': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'tried': 0.27; 'function': 0.29; '"",': 0.31; 'pickle': 0.31; 'file': 0.32; 'lists': 0.32; 'received:169.254': 0.32; 'open': 0.33; 'url:python': 0.33; '(most': 0.33; 'accuracy': 0.36; 'charset:us-ascii': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'should': 0.36; 'received:169': 0.37; 'url:library': 0.38; 'to:addr:python- list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'according': 0.40; 'information,': 0.61; 'purchase': 0.65; 'to:addr:gmail.com': 0.65; 'subject': 0.69; 'legal': 0.71; 'sale': 0.75; 'received:169.254.8': 0.84 |
| X-DKIM | OpenDKIM Filter v2.1.3 sj1.jpmchase.com r6QKhOxd004932 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1374871404; bh=GH2UI94K5MkB8Iyzbfxjqyj3RhxKD12495/Wl7CPah0=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:content-transfer-encoding:MIME-Version; b=T6xWdD/6JC1+2chZsMGmXduGLEJhUdRN16BDFifVNbyvsJZ6OZVoWAp8fCEChPett ChdFI4/c4ZKXpIFSbh805uXrIJu4eTQFhTE8UCDZLsGtCaAmXEMe3HQopHgCfoKSM4 5CR2t2u1wJuDL7Z0ZBOl9v65jto7xH7EdWi/Itm0= |
| X-AuditID | a959a269-b7f038e000006bc2-e6-51f2df6b78e5 |
| From | "Prasad, Ramit" <ramit.prasad@jpmorgan.com> |
| To | cerr <ron.eggler@gmail.com>, "python-list@python.org" <python-list@python.org> |
| Subject | RE: dump a multi dimensional dictionary |
| Thread-Topic | dump a multi dimensional dictionary |
| Thread-Index | AQHOij483aZKA/AWH0iE+R3tCXNKFJl3a70Q |
| Date | Fri, 26 Jul 2013 20:40:54 +0000 |
| References | <efdc6f6b-c061-4d3d-9d02-c397f8953d93@googlegroups.com> |
| In-Reply-To | <efdc6f6b-c061-4d3d-9d02-c397f8953d93@googlegroups.com> |
| Accept-Language | en-US |
| Content-Language | en-US |
| X-MS-Has-Attach | |
| X-MS-TNEF-Correlator | |
| x-originating-ip | [10.67.79.47] |
| Content-Type | text/plain; charset="us-ascii" |
| content-transfer-encoding | quoted-printable |
| MIME-Version | 1.0 |
| X-DLP-FWD | Yes |
| X-Brightmail-Tracker | H4sIAAAAAAAAA+NgFmpjk+LIzCtJLcpLzFFi42JZGSgRrJt9/1Ogwb8/NhZHWq+xWry73sLk wOSxc9Zddo8X89+wBTBFNTDaJObl5ZcklqQqpKQWJ9squWQWJ+ckZuamFinoKngV5OYXpSfm 6SXn5yopZKbYKpkoKRTkJCan5qbmldgqJRYUpOalKNlxKWAAG6CyzDyF1Lzk/JTMvHRbJc9g f10LC1NLXUMlu5CMzGKF1NzEzByFhI3sGcc+7GQpeMtRcW7LN5YGxnNsXYycHBICJhLvvv9k hrDFJC7cWw8U5+IQEjjMKDF10xd2COcAo8Tcvh9Qzn5GibevPrBCOBsZJaZcfM4C0s8mYChx /OwToCoODhGBEInWvyYgYWEBA4kZ076CrRABKln6eDE7hG0kseTYLbBWFgFViU/vz4PFeYFa z02YCRYXEnCW+N/6jQlkJKeAi8TyT2BXMwJd+v3UGiYQm1lAXOLWk/lMEB8ISCzZcx7qG1GJ l4//sULY8hIvprxkg6jXkViw+xOUrS2xbOFrZoi1ghInZz5hAVklJKAmsW+9LYgpIcAnsb2t egKj5Cwky2YhGTQLyaBZSAYtYGRZxShZnJueZqZXXFakV1qsl1WQm5yRWJyql5dasokRlHwi F2XuYPy8yPYQowAHoxIPr8fET4FCrIllxZW5hxglOJiVRHjZg44ECvGmJFZWpRblxxeV5qQW H2KsAgbZRGYp0eR8YGLMK4k3NDazMDA1NTSwMDQyoYqwkjivy9pngUIC6cBUm52aWpBaBLOc iYNTqoGxyUgkQ6lFhCXavG72gaNBJa//lzMWLe9e1ZDO9mgKQ9PGdFPhllmsUjtmnfq8lDdL cak33+EjM5rPJKSs3vTx2Mc5Mjc17+Q0vri9uuCYztuAO9kqnnub9waYFT7zClhSmdFXqnsv vmpXyz9zmYMGz/avSc/f2tXzdq9JAa+eVcubDUUzLHyVWIozEg21mIuKEwFQ3d/NmQMAAA== |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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.5156.1374874858.3114.python-list@python.org> (permalink) |
| Lines | 47 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1374874858 news.xs4all.nl 15877 [2001:888:2000:d::a6]:48364 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:51322 |
Show key headers only | View raw
cerr wrote:
> Hi,
>
> Can I somehow use pickle.dump() to store a dictionary of lists to a file?
> I tried this:
>
> >>> import pickle
> >>> mylist = []
> >>> mydict = {}
> >>> mylist = '1','2'
> >>> mydict['3'] = mylist
> >>> fhg = open ("test", 'w')
> >>> pickle.dump(fhg,mydict)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/lib/python2.7/pickle.py", line 1370, in dump
> Pickler(file, protocol).dump(obj)
> File "/usr/lib/python2.7/pickle.py", line 203, in __init__
> self.write = file.write
> AttributeError: 'dict' object has no attribute 'write'
> >>> print mydict
> {'3': ('1', '2')}
>
> or should I just write my own dump function that can hanle thiS?
>
> Please advise!
>
> Thanks,
> Ron
I think you have the parameters for dump backwards.
According to API http://docs.python.org/2/library/pickle.html#pickle.dump
the format is: pickle.dump(obj, file, protocol=None)
Which means you need to use: pickle.dump(mydict, fhg)
Ramit
This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
dump a multi dimensional dictionary cerr <ron.eggler@gmail.com> - 2013-07-26 13:21 -0700 Re: dump a multi dimensional dictionary John Gordon <gordon@panix.com> - 2013-07-26 21:00 +0000 RE: dump a multi dimensional dictionary "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2013-07-26 20:40 +0000 Re: dump a multi dimensional dictionary Chris Angelico <rosuav@gmail.com> - 2013-07-27 00:33 +0100 Re: dump a multi dimensional dictionary Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-27 02:54 +0000
csiph-web