[Python-ideas] New PEP proposal -- Pathlib Module Should Contain All File Operations

Chris Angelico rosuav at gmail.com
Thu Mar 15 13:58:24 EDT 2018


On Fri, Mar 16, 2018 at 4:48 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Fri, 16 Mar 2018 04:15:11 +1100
> Chris Angelico <rosuav at gmail.com> wrote:
>> On Fri, Mar 16, 2018 at 12:38 AM, George Fischhof <george at fischhof.hu> wrote:
>> >
>> >
>> > " if new file functions are added, they will go only in pathlib,
>> >   which makes pathlib effectively mandatory;"
>> > Yes but I think this part of the evolution: slowly everyone will shift to
>> > pathlib,
>> > and being mandatory is true for the current status as well: if you need a
>> > function, you need the module.
>> > Right now if you wan to execute some file operations, you need os plus
>> > shutil, because the half of the
>> > functions are in one of them, the other half is in the other module
>>
>> The os module is cheap; pathlib has a definite cost. If every file
>> operation goes through pathlib, that basically means pathlib becomes
>> part of the startup cost:
>>
>> rosuav at sikorsky:~$ python3 -m timeit -s 'import subprocess, sys,
>> pathlib' 'subprocess.check_call([sys.executable, "-c", "import os"])'
>> 50 loops, best of 5: 8.82 msec per loop
>> rosuav at sikorsky:~$ python3 -m timeit -s 'import subprocess, sys,
>> pathlib' 'subprocess.check_call([sys.executable, "-c", "import
>> pathlib"])'
>> 20 loops, best of 5: 15.9 msec per loop
>
> Which version is this "python3"?

3.8, but I also tested with 3.7, 3.6, and 3.5. All of them showed the
same kind of difference, but the numbers were a bit higher in the
older versions. I fully expect that Python 3.4 (the first one where
pathlib existed) would show the same too.

ChrisA


More information about the Python-ideas mailing list