How can I verify if the regex exist in a file without reading ?

francois.rabanel at outscale.com francois.rabanel at outscale.com
Fri Jun 15 04:01:03 EDT 2018


Le vendredi 15 juin 2018 02:42:12 UTC+2, Cameron Simpson a écrit :
> 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>


Thanks you a lot for all your tips ! They helps me a lot :) 
I'm beginner in python, this is an excercise I'm trying to realise.

I gonna read more about exceptions and .splitex() !

I work with a file which contains millions lines, a simply file.read() and I'm running out of memory


François



More information about the Python-list mailing list