Python vs. Perl, which is better to learn?

Alex Martelli aleax at aleax.it
Thu May 2 11:13:09 EDT 2002


Aahz wrote:
        ...
> What I'd like is an argument to specify how many command-line args to
> skip over, say if you're writing something like grep.py.

import fileinput, sys, re
there = re.compile(sys.argv.pop(1))
for line in fileinput.input():
    if there.search(line): print line,

Normally, you'd also use options-processing (not to mention error
checking), but even then you get a separate list of real, non-option
args that you can slice or pop things off before passing it on to
fileinput.input.  I'm just lazy in not wanting to map glob.glob over
said list and flatten the results iff I'm on a platform with a
nonglobbingbydefault shell... I'd rather have fileinput.input optionally 
do it for me iff the platform needs it:-).  Perhaps unwise...


Alex




More information about the Python-list mailing list