[Python-ideas] os.listdir default to '.'
cs at zip.com.au
Thu Jan 12 22:32:23 CET 2012
On 12Jan2012 15:14, Rob Cliffe <rob.cliffe at btinternet.com> wrote:
| In Python 2.5 you can at least say os.listdir('') which had the same effect.
| In Python 2.7 you can't.
| Strictly speaking I think the default value should be
| os.path.curdir, not specifically '.'
| +1 from me
I think it should be '.'.
It is possible to arrange directory permissions so that you can't open
curdir because it traverses a directory to which one lacks permissions,
but you can still open '.'. Correspondingly, there can be times you can
opendir('.') but not compute curdir (for access reasons); an unpleasant
situation but possible (maybe not on platforms where the OS hands you
curdir like Linux; historically UNIX platforms compute it by consulting
the mount table and walking some directories.
| +1 on allowing the empty string argument again (may avoid breaking
| some old code)
I used to be a fan of the '' UNIX string referring to the current
directory (on the tenuous but cool logic that '' lets the kernel hand you
the current directory directly, while '.' implies _opening_ the current
directory and finding its '.' entry, and opening that:-) but not any
more - it makes more trouble than its worth (and I think it went away
'.' has better lexical properties than '' - it makes dirname and basename and
similar operations easier to code and think about because it is not an empty
opendir() should be as thin a glue around the OS's opendir as possible.
On that basis I'm good with a default argument value but bad on explicitly
supporting '' as meaning the current directory when the OS may not;
it would at least mean wiring special knowledge into os.opendir for
I guess I'm:
+1 for '.' being opendir's default.
-0.5 for '' being opendir's default.
-1 for os.curdir() being opendir's default.
Cameron Simpson <cs at zip.com.au> DoD#743
I'M NOT afraid of insects talking over the world, and you know why? It would
take about a billion ant just to aim a gun at me, let alone fire it. And
know what I'm doing while they're aiming ti at me? I just sort of slip off
to the side, and then suddenly run up and kick the gun out of their hands.
- Jack Handey
More information about the Python-ideas