Searching for the best scripting language,
Carl Banks
imbosol at aerojockey.invalid
Mon Jun 14 18:09:55 EDT 2004
Ryan Paul wrote:
> The proof is in the source. This is part of a ruby program I wrote. This
> snippet is actually a single 'line'. I broke it into several lines for
> slightly improved readability. This single line would probably take at
> least 15 lines to do in python, probably more if you wanted to do it
> intelligently.
>
> ["*.rar.*", "*.r[0-9][0-9].*"].each {|fn|
> Dir[$prefix+fn].collect {|x|
> x.gsub(/\.\d+[\d.-]*$/,"")}.uniq.each {|x|
> `cat #{sesc x}.* > #{sesc x}`} }
Oh boy. I believe this untested Python code does what you want, also
one line, also wrapped in the name of "clarity."
for f in dict([(__import__('re').sub(r"\.\d+[\d.-]*$","",x),None)
for fn in ("*.rar.*","*.r[0-9][0-9].*")
for x in __import__('glob').glob(prefix+fn)]):
__import__('os').system("cat %s.* > %s" % (sesc(f),sesc(f)))
This would take about 7 lines in well-written Python, not 15.
bad-code-can-be-written-in-any-language-ly yr's,
--
CARL BANKS http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work."
-- Parody of Mr. T from a Robert Smigel Cartoon
More information about the Python-list
mailing list