How to Access Unix Shell

Paul Watson pwatson at redlinepy.com
Tue Jun 15 10:11:39 EDT 2004


"Neale" <nhirsh2 at ieee.org> wrote in message
news:2d7af4f8.0406140615.310f1875 at posting.google.com...
> > > > [[snip]]
> > > How about :
> > > ===
> > > files = os.listdir(".")
> > > ===
> > >
> > > Bye.
> > > --
> >
> -------------------------------------------------------------------------
> > > Miki Tebeka <miki.tebeka at zoran.com>
> >
> > Well, I could claim that I knew about listdir but was simply answering
the
> > 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
with
> > wx(Python|Widgets) so I rarely use the python system stuff) , so I thank
you
> > 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 http://docs.python.org/modindex.html might also be good material.

Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> dir(os)
['F_OK', 'O_APPEND', 'O_BINARY', 'O_CREAT', 'O_EXCL', 'O_NOINHERIT',
'O_RANDOM', 'O_RDONLY', 'O_RDWR', 'O_SEQUENTIAL', '
O_SHORT_LIVED', 'O_TEMPORARY', 'O_TEXT', 'O_TRUNC', 'O_WRONLY', 'P_DETACH',
'P_NOWAIT', 'P_NOWAITO', 'P_OVERLAY', 'P_WAI
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