Trying to decide between PHP and Python

Google Poster goposter at jonjay.com
Tue Jan 4 16:22:41 EST 2011


On Jan 4, 3:09 pm, Alex Willmer <a... at moreati.org.uk> wrote:
> On Jan 4, 8:20 pm, Google Poster <gopos... at 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


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /