How to Access Unix Shell

Paul Watson pwatson at
Tue Jun 15 16:11:39 CEST 2004

"Neale" <nhirsh2 at> wrote in message
news:2d7af4f8.0406140615.310f1875 at
> > > > [[snip]]
> > > How about :
> > > ===
> > > files = os.listdir(".")
> > > ===
> > >
> > > Bye.
> > > --
> >
> -------------------------------------------------------------------------
> > > Miki Tebeka <miki.tebeka at>
> >
> > Well, I could claim that I knew about listdir but was simply answering
> > original question which was how to run arbitrary shell commands.
> >
> > But in fact I knew nothing of listdir (all of my coding so far has been
> > wx(Python|Widgets) so I rarely use the python system stuff) , so I thank
> > for the education :-).
> >
> > Pax.
> Thank you for such high quality help.
> If there are other Unix command functions like listdir, where/how do I
> find them? Is there a particular directory in Python, maybe?

You could look at all of the items in the os module.  The module directory
at might also be good material.

Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> dir(os)
T', 'R_OK', 'TMP_MAX', 'UserDict', 'W_OK', 'X_OK', '_Environ', '__all__',
'__builtins__', '__doc__', '__file__', '__name
__', '_copy_reg', '_execvpe', '_exists', '_exit', '_get_exports_list',
'_make_stat_result', '_make_statvfs_result', '_pi
ckle_stat_result', '_pickle_statvfs_result', 'abort', 'access', 'altsep',
'chdir', 'chmod', 'close', 'curdir', 'defpath'
, 'dup', 'dup2', 'environ', 'error', 'execl', 'execle', 'execlp', 'execlpe',
'execv', 'execve', 'execvp', 'execvpe', 'ex
tsep', 'fdopen', 'fstat', 'fsync', 'getcwd', 'getcwdu', 'getenv', 'getpid',
'isatty', 'linesep', 'listdir', 'lseek', 'ls
tat', 'makedirs', 'mkdir', 'name', 'open', 'pardir', 'path', 'pathsep',
'pipe', 'popen', 'popen2', 'popen3', 'popen4', '
putenv', 'read', 'remove', 'removedirs', 'rename', 'renames', 'rmdir',
'sep', 'spawnl', 'spawnle', 'spawnv', 'spawnve',
'startfile', 'stat', 'stat_float_times', 'stat_result', 'statvfs_result',
'strerror', 'sys', 'system', 'tempnam', 'times
', 'tmpfile', 'tmpnam', 'umask', 'unlink', 'unsetenv', 'utime', 'waitpid',
'walk', 'write']
>>> print os.listdir.__doc__
listdir(path) -> list_of_strings

Return a list containing the names of the entries in the directory.

        path: path of directory to list

The list is in arbitrary order.  It does not include the special
entries '.' and '..' even if they are present in the directory.

More information about the Python-list mailing list