How can I verify if the regex exist in a file without reading ?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu Jun 14 20:24:31 EDT 2018
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.
> Importantly:
>
> os.rename(path, new_filename)
>
> The old name comes first, then the new name.
Oops! I forgot about that.
--
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson
More information about the Python-list
mailing list