sth is right. You can also use os.popen(), but where available
(Python 2.4+) subprocess is generally preferable. However,
unlike some languages that encourage it, it's generally
considered bad form to spawn a subprocess where you can do the
same job inside the language. It's slower, less reliable and
platform-dependent. Your example would be better off as: baz is
a directory and I'm trying to get the contents of all the files
in that directory ? cat on a directory gets me an error. If you
want a list of files: If you want the contents of all files in a
directory, something like: for leaf in os.listdir('/tmp/baz'):
path= os.path.join('/tmp/baz', leaf) or, if you can be sure
there are no directories in there, you could fit it in a one-
liner: foo= ''.join(open(os.path.join(path, child), 'rb').read()
for child in os.listdir(path))