[Tutor] Need help printing a pickled data

Matt D md123 at nycap.rr.com
Tue Jun 25 14:19:41 CEST 2013


On 06/25/2013 07:28 AM, eryksun wrote:
> On Mon, Jun 24, 2013 at 6:57 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>>
>> You certainly shouldn't be writing pickle data to a log file! Firstly,
>> log files are usually opened in text mode, not binary mode, so it
>> probably won't work, and secondly even if it did work, you will be
>> dumping a load of pickled binary data into the middle of what should be
>> a text file. That's a bad idea. And even if it succeeded, what are you
>> going to learn from seeing a line like this:
> 
> I don't know which version Matt is using, but 2.x defaults to pickle
> protocol 0, which is ASCII. In 3.x you can manually specify protocol
> 0:
> 
>     >>> pickle.dumps([1,2,3], protocol=0)
>     b'(lp0\nL1L\naL2L\naL3L\na.'
> 
> With the ASCII protocol you can open the file in either text or binary
> mode, so long as you're consistent. But use binary mode if it needs to
> be cross-platform.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
I'm using 2.7 for this program.  I the docs say what you said about the
default being 0 so I didn't know I needed to convert to string.
Thanks.


More information about the Tutor mailing list