[Python-ideas] os.listdir default to '.'

Masklinn masklinn at masklinn.net
Thu Jan 12 16:22:42 CET 2012

On 2012-01-12, at 16:02 , Michael Foord wrote:
> Hello all,
> I frequently use Python from the interactive interpreter as a shell. It is
> a frequent, but mild, irritant that I have to type os.listdir('.') instead
> of just os.listdir().
> How about making '.' a default argument for os.listdir ?
I was going to say I don't think '.' is a good idea for `os.listdir`, but

> ls
Doc               LICENSE           Makefile          Misc              PC                Python            build             configure         pybuilddir.txt    python.exe
Grammar           Lib               Makefile.pre      Modules           PCbuild           README            config.log        configure.in      pyconfig.h        python.exe-gdb.py
Include           Mac               Makefile.pre.in   Objects           Parser            Tools             config.status     install-sh        pyconfig.h.in     setup.py
> python3.2
Python 3.2.2 (default, Nov  7 2011, 20:32:23) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.listdir()
['.bzrignore', '.gitignore', '.hg', '.hgcheck', '.hgeol', '.hgignore', '.hgtags', 'build', 'config.log', 'config.status', 'configure', 'configure.in', 'Doc', 'Grammar', 'Include', 'install-sh', 'Lib', 'LICENSE', 'Mac', 'Makefile', 'Makefile.pre', 'Makefile.pre.in', 'Misc', 'Modules', 'Objects', 'Parser', 'PC', 'PCbuild', 'pybuilddir.txt', 'pyconfig.h', 'pyconfig.h.in', 'Python', 'python.exe', 'python.exe-gdb.py', 'README', 'setup.py', 'Tools']

looks like '.' is already the default argument for os.listdir in Python 3.2 (but not in 3.1, no idea about 3.3)

More information about the Python-ideas mailing list