How can I verify if the regex exist in a file without reading ?
Cameron Simpson
cs at cskk.id.au
Thu Jun 14 20:41:53 EDT 2018
On 15Jun2018 00:24, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
>On Fri, 15 Jun 2018 10:00:59 +1000, Cameron Simpson wrote:
>> Francois, unless your regex can cross multiple lines it is better to
>> search files like this:
>>
>> with open(the_filename) as f:
>> for line in f:
>> ... search the line for the regexp ...
>>
>> That way you only need to keep one line at a time in memory.
>
>That's what François is doing.
Urr, so he is. Then like you, I don't know why he's concerned about running out
of memory. Unless it hasn't been made clear the Python will free up unused
memory on its own.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Python-list
mailing list