--h31gzZEtNLTqOjlF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This is my first exposure to the Python language, and I have found many things to my liking. I have also noticed some quirks which I regard as assumption flaws on part of the interpreter. The one I am interested in at the moment is the assumption that we should leave the . and .. directory entries out of the directory listing returned by os.listdir(). I have read the PEP specification and have thereby prepared a PEP for your perusal. I hope you agree with me that this is both a philosophical issue based in tradition as well as a duplication of effort problem that can be readily solved with regards to backwards compatibility. Thank you. I have attached the PEP to this message. Sincerely, Nelson Rush "This most beautiful system [The Universe] could only proceed from the dominion of an intelligent and powerful Being." -- Sir Isaac Newton --h31gzZEtNLTqOjlF Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=pep-ldir PEP: Title: os.listdir Full Directory Listing Version: Author: palisade@users.sourceforge.net (Nelson Rush) Status: Type: Created: 16/3/2001 Post-History: Introduction This PEP explains the need for two missing elements in the list returned by the os.listdir function. Proposal It is obvious that having os.listdir() return a list with . and .. is going to cause many existing programs to function incorrectly. One solution to this problem could be to create a new function os.listdirall() or os.ldir() which returns every file and directory including the . and .. directory entries. Another solution could be to overload os.listdir's parameters, but that would unnecessarily complicate things. Key Differences with the Existing Protocol The existing os.listdir() leaves out both the . and .. directory entries which are a part of the directory listing as is every other file. Examples import os dir = os.ldir('/') for i in dir: print i The output would become: . .. lost+found tmp usr var WinNT dev bin home mnt sbin boot root man lib cdrom proc etc info pub .bash_history service Dissenting Opinion During a discussion on Efnet #python, an objection was made to the usefulness of this implementation. Namely, that it is little extra effort to just insert these two directory entries into the list. Example: os.listdir() + ['.','..'] An argument can be made however that the inclusion of both . and .. meet the standard way of listing files within directories. It is on basis of this common method between languages of listing directories that this tradition should be maintained. It was also suggested that not having . and .. returned in the list by default is required to be able to perform such actions as `cp * dest`. However, programs like `ls` and `cp` list and copy files excluding any directory that begins with a period. Therefore there is no need to clip . and .. from the directory list by default. Since anything beginning with a period is considered to be hidden. Reference Implementation The reference implementation of the new dircache.py core ldir function extends listdir's functionality as proposed. http://palisade.rm-f.net/dircache.py Copyright This document has been placed in the Public Domain. --h31gzZEtNLTqOjlF--
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4