speed of string chunks file parsing

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Mon Apr 6 17:24:20 CEST 2009


bearophile:
>     cp_regular_expression = re.compile("^a complex regular expression
> here$")
>     for line in file(inputfile):
>         if cp_regular_expression.match(line) and result_seq:

Sorry, you can replace that with:

    cp_regular_expression = re.compile("^a complex regular expression
here$").match
    for line in file(inputfile):
        if cp_regular_expression(line) and result_seq:

That is a bit faster.

Bye



More information about the Python-list mailing list