Searching for the best scripting language,
Carl Banks
imbosol at aerojockey.invalid
Mon Jun 14 18:49:09 EDT 2004
Steve Lamb wrote:
>
>
> On 2004-06-14, Carl Banks <imbosol at aerojockey.invalid> wrote:
>> Ryan Paul wrote:
>>> ["*.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,
>
> Ok, see, here's the thing. I look at the Ruby code and can kind
> of follow it. I look at the Python code and can kind of follow it.
> but in neither case have I, in glancing here and there today, been
> able to decipher exactly what is going on. Care to show the 5 line
> long form to see if I get that? No explination, just curious to see
> if I can get it reading real code instead of hacked up line noise.
Of course you can.
import glob
import os
import re
f = {}
for pattern in ("*.rar.*","*.r[0-9][0-9].*"):
for listing in glob.glob(prefix+pattern):
f[listing] = None
for filename in f:
os.system("cat %s.* > %s" % (sesc(filename),sesc(filename)))
I don't know what sesc is. I assume he had defined it elsewhere,
because he said this was only part of a script he wrote (and that's
what scares me--I can understand a throwaway one-liner looking like
this, but not a line in a script).
--
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