On Jan 4, 3:09 pm, Alex Willmer <a...@moreati.org.uk> wrote: > On Jan 4, 8:20 pm, Google Poster <gopos...@jonjay.com> wrote: > > > Can any of you nice folks post a snippet of how to perform a listing > > of the current directory and save it in a string? > > > Something like this: > > > $ setenv FILES = `ls` > > > Bonus: Let's say that I want to convert the names of the files to > > lowercase? As 'tolower()' > > I'd just like to mention one more python nicety: list comprehension. > If you wanted the filenames as a list of strings, with each made > lowercase then the following would serve well: > > import os > filenames = os.listdir('.') > filenames_lower = [fn.lower() for fn in filenames] > > You could also combine this into one line: > > import os > filenames_lower = [fn.lower() for fn in os.listdir('.')] > > Regards, Alex
The syntax reminds me of Lots of Interspersed Silly Parentheses (L.I.S.P.), but without the parentheses. :-) -Ramon -- http://mail.python.org/mailman/listinfo/python-list