<p dir="ltr"><br>
On 14 Jul 2014 22:50, "Ben Hoyt" <<a href="mailto:benhoyt@gmail.com">benhoyt@gmail.com</a>> wrote:<br>
><br>
> In light of that, I propose I update the PEP to basically follow<br>
> Victor's model of is_X() and stat() following symlinks by default, and<br>
> allowing you to specify follow_symlinks=False if you want something<br>
> other than that.<br>
><br>
> Victor had one other question:<br>
><br>
> > What happens to name and full_name with followlinks=True?<br>
> > Do they contain the name in the directory (name of the symlink)<br>
> > or name of the linked file?<br>
><br>
> I would say they should contain the name and full path of the entry --<br>
> the symlink, NOT the linked file. They kind of have to, right,<br>
> otherwise they'd have to be method calls that potentially call the<br>
> system.</p>
<p dir="ltr">It would be worth explicitly pointing out "os.readlink(entry.full_name)" in the docs as the way to get the target of a symlink entry.</p>
<p dir="ltr">Alternatively, it may be worth including a readlink() method directly on the entry objects. (That can easily be added later though, so no need for it in the initial proposal).</p>
<p dir="ltr">><br>
> In any case, here's the modified proposal:<br>
><br>
> scandir(path='.') -> generator of DirEntry objects, which have:<br>
><br>
> * name: name as per listdir()<br>
> * full_name: full path name (not necessarily absolute), equivalent of<br>
> os.path.join(path, <a href="http://entry.name">entry.name</a>)<br>
> * is_dir(follow_symlinks=True): like os.path.isdir(entry.full_name),<br>
> but free in most cases; cached per entry<br>
> * is_file(follow_symlinks=True): like os.path.isfile(entry.full_name),<br>
> but free in most cases; cached per entry<br>
> * is_symlink(): like os.path.islink(), but free in most cases; cached per entry<br>
> * stat(follow_symlinks=True): like os.stat(entry.full_name,<br>
> follow_symlinks=follow_symlinks); cached per entry<br>
><br>
> The above may not be quite perfect, but it's good, and I think there's<br>
> been enough bike-shedding on the API. :-)</p>
<p dir="ltr">+1, sounds good to me (and I like having the caching guarantees listed - helps make it clear how DirEntry differs from pathlib.Path)</p>
<p dir="ltr">Cheers,<br>
Nick.</p>
<p dir="ltr">><br>
> So please speak now or forever hold your peace. :-) I intend to update<br>
> the PEP to reflect this and make a few other clarifications in the<br>
> next few days.<br>
><br>
> -Ben<br>
> _______________________________________________<br>
> Python-Dev mailing list<br>
> <a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-dev">https://mail.python.org/mailman/listinfo/python-dev</a><br>
> Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com">https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com</a><br>
</p>