lkml.org 
[lkml]   [2019]   [Jan]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v2] perf scripts python: Add Python 3 support to exported-sql-viewer.py
From
Date
On 1/20/19 11:27 AM, Jonathan Corbet wrote:
> On Fri, 18 Jan 2019 16:45:04 -0800
> Tony Jones <tonyj@suse.de> wrote:
>
>> On 1/17/19 1:45 AM, Seeteena Thoufeek wrote:
>>
>>> +if sys.version_info[0] < 3:
>>> + import cPickle
>>> +else:
>>> + import _pickle as cPickle
>>
>> Do you really need this?
>>
>> pickle is already in Python2.
>
> Did you mean in Python3? I would agree that using it is better than
> importing the semi-hidden _pickle module.

No. I meant Python2 :)

pickle in Python2 is the python implementation
cPickle in Python2 is the C implementation.

Read: https://docs.python.org/3.1/whatsnew/3.0.html#library-changes
A common pattern in Python 2.x is to have one version of a module implemented in pure Python, with an optional accelerated version implemented as a C extension; for example, pickle and cPickle. This places the burden of importing the accelerated version and falling back on the pure Python version on each user of these modules. In Python 3.0, the accelerated versions are considered implementation details of the pure Python versions. Users should always import the standard version, which attempts to import the accelerated version and falls back to the pure Python version.

I my patchset "import pickle" was sufficient for Python2 and Python3 The question I suppose is whether this script, for Python2, needs the accelerated C implementation. I decided it didn't.

Tony

\
 
 \ /
  Last update: 2019-01-21 08:25    [W:0.114 / U:7.308 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site