output from external commands

Kent Johnson kent37 at tds.net
Mon Oct 24 13:53:12 CEST 2005


darren kirby wrote:
> quoth the James Colannino:
>>So, for example, in Perl I could do something like:
>>
>>@files = `ls`;
>>
>>So I guess I'm looking for something similiar to the backticks in Perl.
>>Forgive me if I've asked something that's a bit basic for this list.
>>Any help would be greatly appreciated :)  Thanks very much in advance.
> 
> 
> If all you want is filenames this will work:
> 
>>>>import glob
>>>>files = ["%s" % f for f in glob.glob("*")]

or
import os
files = os.listdir('.')

Python has built-in support for many file manipulations, see the os, os.path and shutil modules.

Kent



More information about the Python-list mailing list