merging uniq -c lists

Giorgos Keramidas keramida at ceid.upatras.gr
Thu Dec 27 15:08:37 EET 2007


On 2007-12-27 15:00, Giorgos Keramidas <keramida at ceid.upatras.gr> wrote:
> % def dispatch(uniq, fp):
> %     lineno = 0
> %     for l in fp.readlines(8192):
> %         lineno += 1
> %         match = ure.match(l)
> %         if not match:
> %             err("%s: %s: line %d: ignoring line (not enough fields)\n" % \
> %                 (progname, fname, lineno))
> %             continue
> %         (count, tag) = match.groups()
> %         count = int(count)
> %         try:
> %             count += int(uniq[tag])
> %         except KeyError:
> %             pass
> %         uniq[tag] = int(count)
> %     return None

Το οποίο έχει ένα μικρό bug (δεν ορίζεται `fname' πουθενά):

    if not match:
        fname = fp.__getattribute__('name')
        err("%s: %s: line %d: ignoring line (not enough fields)\n" % \
            (progname, fname, lineno))
    ...

Αυτά παθαίνει όποις αλλάζει το API της dispatch() από filename σε fp,
χωρίς test case :P




More information about the Linux-greek-users mailing list