<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2018-03-13 13:17 GMT+01:00 Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Mon, Mar 12, 2018 at 09:57:32PM +0100, George Fischhof wrote:<br>
<br>
> Right now we have several modules that contain functions related<br>
> to file-system operations mainly the os, pathlib and shutil.<br>
> For beginners it is quite hard to remember where can he / she find<br>
> a function (copy resides in shutil, but the remove function can be<br>
> found in the os module.  (And sometimes developers with moderate<br>
> experience have to check the documentation as well.)<br>
<br>
</span>This is certainly a problem. Not a big problem, but it is an annoyance.<br>
<span class="gmail-"><br>
<br>
> With functions in pathlib the developers should not have to think<br>
> on which method (function) can be found in which module.<br>
><br>
> Makes the life easier.<br>
<br>
</span>I don't know that this will be true. It makes one problem better: you no<br>
longer have to remember which module the function is in. But it makes<br>
other things worse:<br>
<br>
- code and/or API duplication: for backwards compatibility, every<br>
  existing function must be in two places, the original and in<br>
  pathlib;<br>
<br>
- if new file functions are added, they will go only in pathlib,<br>
  which makes pathlib effectively mandatory;<br>
<br>
- the pathlib API becomes even more complicated: not only have you<br>
  got all the methods of pathlib objects, but you have all the shutil<br>
  and os functions as well.<br>
<br>
<br>
I think this is a good place for an experiment. You could write a<br>
function which monkey-patches pathlib:<br>
<br>
from pathlib import Path<br>
import os<br>
import shutil<br>
<br>
def monkeypatch():<br>
    Path.remove = os.remove<br>
    # etc.<br>
<br>
Then we can see how many functions are involved, how large this makes<br>
the Path object, and try it out and see whether it is better.<br>
<span class="gmail-HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
Steve<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</font></span></blockquote></div><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Duplication: it is true, but it is true for several other modules as well. </div><div class="gmail_extra">I checked the pathlib module: right now more than 50% of the functions are duplicate  </div><div class="gmail_extra">- mainly from os - so it seems that pathlib already started to develop this way ;-)</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">"

<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">if new file functions are added, they will go only in pathlib,</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">  which makes pathlib effectively mandatory;"</span></div><div class="gmail_extra"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Yes but I think this part of the evolution: slowly everyone will shift to pathlib, </span></div><div class="gmail_extra"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">and being mandatory is true for the current status as well: if you need a function, you need the module. </span></div><div class="gmail_extra"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Right now if you wan to execute some file operations, you need os plus shutil, because the half of the </span></div><div class="gmail_extra"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">functions are in one of them, the other half is in the other module</span></div><div class="gmail_extra"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div class="gmail_extra"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div class="gmail_extra"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I collected the functions that sould be put into pathlib:</span></div><div class="gmail_extra"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div class="gmail_extra"><span style="text-align:start;text-indent:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><div class="gmail_extra">- os.remove</div><div class="gmail_extra"><br></div><div class="gmail_extra">- os.removedirs (shutil.rmtree has the same functionalaty)<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">- os.truncate<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">- shutil.copyfileobj<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">- shutil.copyfile<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">- shutil.copymode<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">- shutil.copystat<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">- shutil.copy<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">- shutil.copy2</div><div class="gmail_extra"><br></div><div class="gmail_extra">- shutil.copytree with shutil.ignore_patterns</div><div class="gmail_extra"><br></div><div class="gmail_extra">- shutil.move</div><div class="gmail_extra"><br></div><div class="gmail_extra">- shutil.disk_usage<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">- shutil.chown</div><div class="gmail_extra"><div class="gmail_extra"><br></div><div class="gmail_extra">- os.link => path.hardlink_to</div><div class="gmail_extra"><br></div><div class="gmail_extra">- os.mkfifo</div><div class="gmail_extra"><br></div><div class="gmail_extra">- os.readlink</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Sum: 16 functuins</div><div class="gmail_extra">And 

<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">all functions from os module accept path-like objects, and none of the shutil functions.</span></div><div class="gmail_extra"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Pathlib already contains 17 functions from os an shutil modules.</span></div><div class="gmail_extra"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div class="gmail_extra"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div class="gmail_extra"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">George</span></div></div></span></div></div>