Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41116 > unrolled thread
| Started by | Jean-Michel Pichavant <jeanmichel@sequans.com> |
|---|---|
| First post | 2013-03-12 12:54 +0100 |
| Last post | 2013-03-14 11:22 +1100 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
Re: Store a variable permanently Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-03-12 12:54 +0100
Re: Store a variable permanently Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-13 17:37 +0000
Re: Store a variable permanently Chris Angelico <rosuav@gmail.com> - 2013-03-14 11:22 +1100
| From | Jean-Michel Pichavant <jeanmichel@sequans.com> |
|---|---|
| Date | 2013-03-12 12:54 +0100 |
| Subject | Re: Store a variable permanently |
| Message-ID | <mailman.3223.1363089272.2939.python-list@python.org> |
----- Original Message -----
> On Mon, 11 Mar 2013 11:19:49 +0100, Jean-Michel Pichavant wrote:
>
> [...]
> > While your point about security is fair, the others aren't. Pickle
> > uses
> > by default an ascii representation of the data, it's readable and
> > writeable.
> >
> > import pickle
> > a = 758
> > pickle.dump(a, open('test.pickle', 'w'))
> > !cat test.pickle
> > I758
> > .
>
>
> What is that? It's not Python code, !cat test.pickle gives a syntax
> error.
It's a IPython shell session, !cat test.pickle writes the content of that file to stdout. But I have the feeling you already know that ;)
[snip]
> Pickle is a big module, over 1400 lines, capable of serialising
> almost
> anything. It's a big, powerful hammer for cracking armour-plated
> coconuts. But a single int is pretty much a peanut. Compare pickle's
> 1400
> lines with the dozen or so lines I provided. That is all that I meant
> by
> "overkill".
I would be surprised if the 1400 lines were used to dump an integer. Anyway who cares about the size of the module, a lot of people import sys and os while using only a very subset of it.
And to reuse your analogy, there's nothing wrong cracking a peanut with a hammer as long as you have it in your hands and that it takes absolutely no effort, compared to building your own small peanut cracker. Trying to crack the peanut by landing an airplane on it, that would work *and* be "overkill".
Now about analogies:
http://www.linguistrix.com/blog/?p=456
Cheers,
JM
-- IMPORTANT NOTICE:
The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-03-13 17:37 +0000 |
| Message-ID | <5140b946$0$29965$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #41116 |
On Tue, 12 Mar 2013 12:54:11 +0100, Jean-Michel Pichavant wrote:
>> > import pickle
>> > a = 758
>> > pickle.dump(a, open('test.pickle', 'w'))
>> > !cat test.pickle
>> > I758
>> > .
>>
>>
>> What is that? It's not Python code, !cat test.pickle gives a syntax
>> error.
>
> It's a IPython shell session, !cat test.pickle writes the content of
> that file to stdout. But I have the feeling you already know that ;)
Actually, no, I don't use IPython and am not familiar with it.
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-03-14 11:22 +1100 |
| Message-ID | <mailman.3279.1363220580.2939.python-list@python.org> |
| In reply to | #41187 |
On Thu, Mar 14, 2013 at 4:37 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> On Tue, 12 Mar 2013 12:54:11 +0100, Jean-Michel Pichavant wrote:
>
>>> > import pickle
>>> > a = 758
>>> > pickle.dump(a, open('test.pickle', 'w'))
>>> > !cat test.pickle
>>> > I758
>>> > .
>>>
>>>
>>> What is that? It's not Python code, !cat test.pickle gives a syntax
>>> error.
>>
>> It's a IPython shell session, !cat test.pickle writes the content of
>> that file to stdout. But I have the feeling you already know that ;)
>
> Actually, no, I don't use IPython and am not familiar with it.
Neither do I, but it's fairly clear what it's trying to do :) But
pickle.dumps achieves the same thing in a much better way (the repr()
of a string is more useful here anyway).
ChrisA
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web